//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define ONLINE_JUDGE
void solve() {
int n;
cin >> n;
vector <int> vec(n +1);
for(int i = 1; i <= n; i++)
cin >> vec[i];
vector <double> can;
for(int i = 1; i <= n; i++) {
i64 sum = 0;
for(int j = i; j <= n; j++) {
sum += vec[j];
can.emplace_back(double(1) * sum / (j - i +1));
}
}
i64 top = accumulate(vec.begin(), vec.end(), 0LL);
double ans = 1E18;
for(double &mx : can) {
i64 sum = top;
double mn = double(1) * sum / n;
if(mn > mx) {
continue;
}
int l = 1, r = n;
while(l < r) {
//cerr << l << " " << r << "\n";
if(sum - vec[l] <= mx * (r - l)) {
sum -= vec[l];
l++;
} else {
sum -= vec[r];
r--;
}
mn = min(mn, double(1) * sum / (r - l +1));
}
//cerr << "# " << mx << " " << mn << "\n";
ans = min(ans, mx - mn);
//cerr << "\n";
}
cout << setprecision(15) << ans;
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
2063 ms |
17100 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
2063 ms |
17100 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |