QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#444642#8524. Weather Forecastucup-team3924#WA 1ms4056kbC++14963b2024-06-15 20:35:302024-06-15 20:35:31

Judging History

你现在查看的是最新测评结果

  • [2024-06-15 20:35:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4056kb
  • [2024-06-15 20:35:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int check(long double avg, vector<long double>a){
    for(auto &x : a)x -= avg;
    stack<long double>S;
    int n = a.size();
    long double s = 0;
    bool cb = false;
    for(int i = 0; i < n; i++){
        if(cb && a[i] >= 0){
            S.push(s);
            s = 0;
            cb = false;
        }
        s += a[i];
        if(s >= 0)cb = true;
    }
    if(cb)S.push(s);
    while(s < 0 && !S.empty()){
        s += S.top();
        if(s >= 0)break;
        S.pop();
    }
    return S.size();
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<long double>a(n);
    for(auto &x : a)cin >> x;
    long double l = 1, r = 1000;
    
    
    for(int i = 0; i < 200; i++){
        long double mid = (l + r)/2;
        if(check(mid, a) >= k - 1)l = mid;
        else r = mid;
    }

    cout << fixed << setprecision(12) << l << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3992kb

input:

7 3
1 3 1 2 2 2 1

output:

1.666666666667

result:

ok found '1.66667', expected '1.66667', error '0.00000'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 4056kb

input:

1 1
1

output:

1000.000000000000

result:

wrong answer 1st numbers differ - expected: '1.00000', found: '1000.00000', error = '999.00000'