QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#466659 | #8524. Weather Forecast | El_7la2een# | WA | 0ms | 4056kb | C++20 | 873b | 2024-07-08 00:21:20 | 2024-07-08 00:21:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n, k;
bool check(vector<double>& v, double avg) {
double sum = 0, num = 0;
int cnt = 0;
for (auto& i : v) {
sum += i;
num++;
double av = sum / num;
if (avg <= av) {
cnt++;
sum = 0;
num = 0;
}
}
return (cnt >= k);
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> k;
vector<double>v(n);
for (auto& i : v)cin >> i;
double l = 0, r = 10000;
double ans = 0;
for (int i = 0; i < 60; i++) {
double md = (l + r) / 2.0;
if (check(v, md)) {
ans = md;
l = md;
}
else r = md;
}
cout << fixed << setprecision(12) << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
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: 0
Accepted
time: 0ms
memory: 4056kb
input:
1 1 1
output:
1.000000000000
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3944kb
input:
2 1 2 1
output:
2.000000000000
result:
wrong answer 1st numbers differ - expected: '1.50000', found: '2.00000', error = '0.50000'