QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#442328 | #8524. Weather Forecast | ucup-team3282# | WA | 1ms | 3904kb | C++14 | 1.0kb | 2024-06-15 11:09:32 | 2024-06-15 11:09:33 |
Judging History
answer
#include <bits/stdc++.h>
#define eps 1e-9
using namespace std;
const int N = 2e5+9;
int n, k;
int a[N];
bool check(double mid) {
// cout << mid << "----------------" <<endl;
double cur = 0; int l = 1; double sum = 0;int cc = 0, ans = 0;
while (l <= n && ans < k-1) {
cur = 0;sum = 0;
while (cur < mid && l <= n) {
sum += a[l];
l++; cc++;
cur = (double) (sum / cc);
}
if (l > n) break;
while (cur > mid && a[l] < mid && l<=n) {
sum += a[l];
l++; cc++;
cur = double (sum / cc);
}
cc = 0;
ans++;
// cout<<l-1<<endl;
}
if (cur < mid) return false;
cur = 0;sum = 0;
for(;l<=n;l++){
cc++,sum+=a[l];
}
return sum/cc>=mid;
}
int main() {
// freopen("2.in", "r", stdin);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
double l = 0.0, r = 1e9, ans = 0.0;
// cout << check(1.666) << endl;
while (l + eps < r) {
double mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
l = mid;
} else r = mid;
}
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3904kb
input:
7 3 1 3 1 2 2 2 1
output:
1.66667
result:
ok found '1.66667', expected '1.66667', error '0.00000'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3692kb
input:
1 1 1
output:
0
result:
wrong answer 1st numbers differ - expected: '1.00000', found: '0.00000', error = '1.00000'