#include <cstdio>
#include <numeric>
#include <algorithm>
using namespace std;
int n, a[200006];
double f() {
long long sum = accumulate(a, a + n, 0LL);
double init = sum / (double)n, curr = init;
double mx = curr, mn = curr;
int l = 0, r = n - 1, cnt = n;
while (l < r) {
if (curr < init) sum -= a[l++];
else sum -= a[r--];
cnt--;
curr = sum / (double)cnt;
mx = max(mx, curr);
mn = min(mn, curr);
}
return mx - mn;
}
double g() {
long long sum = accumulate(a, a + n, 0LL);
double init = sum / (double)n, curr = init;
double mx = curr, mn = curr;
int l = 0, r = n - 1, cnt = n;
while (l < r) {
if (curr > init) sum -= a[r--];
else sum -= a[l++];
cnt--;
curr = sum / (double)cnt;
mx = max(mx, curr);
mn = min(mn, curr);
}
return mx - mn;
}
double f2() {
long long sum = accumulate(a, a + n, 0LL);
double init = sum / (double)n, curr = init;
double mx = curr, mn = curr;
int l = 0, r = n - 1, cnt = n;
while (l < r) {
if ((sum - a[r]) / (double)(cnt - 1) >= init) sum -= a[r--];
else sum -= a[l++];
cnt--;
curr = sum / (double)cnt;
mx = max(mx, curr);
mn = min(mn, curr);
}
return mx - mn;
}
double g2() {
long long sum = accumulate(a, a + n, 0LL);
double init = sum / (double)n, curr = init;
double mx = curr, mn = curr;
int l = 0, r = n - 1, cnt = n;
while (l < r) {
if ((sum - a[l]) / (double)(cnt - 1) <= init) sum -= a[l++];
else sum -= a[r--];
cnt--;
curr = sum / (double)cnt;
mx = max(mx, curr);
mn = min(mn, curr);
}
return mx - mn;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", a + i);
printf("%.10f", min({ f(), g(), f2(), g2() }));
}
Compilation message
seesaw.cpp: In function 'int main()':
seesaw.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
seesaw.cpp:74:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | for (int i = 0; i < n; i++) scanf("%d", a + i);
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |