// I was grinning like I'm winning, I was hitting my marks
// 'Cause I can do it with a broken heart
// 1 2 3 4 ...
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
using namespace std;
vector<ll> a, pf;
ld avg(int l, int r) { return (ld)(pf[r + 1] - pf[l]) / (ld)(r - l + 1); }
void chmax(ld& a, ld b) { a = max(a, b); }
void chmin(ld& a, ld b) { a = min(a, b); }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
a.assign(n, 0), pf.assign(n + 1, 0);
for (int i = 0; i < n; i++) cin >> a[i], pf[i + 1] = pf[i] + a[i];
ld ans = a[n - 1];
for (int l = 0; l < n; l++) for (int r = l; r < n; r++)
{
ld c = avg(l, r);
ld mi = avg(0, n - 1);
ld mx = avg(0, n - 1);
if (c > mi || mi - c > ans) continue;
int li = 0, ri = n - 1;
while (li < ri)
{
if (avg(li, ri - 1) >= c) ri--;
else li++;
chmin(mi, avg(li, ri));
chmax(mx, avg(li, ri));
if (mx - mi > ans) break;
}
chmin(ans, mx - mi);
}
cout << setprecision(9) << fixed;
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
69 ms |
484 KB |
Output is correct |
9 |
Correct |
87 ms |
348 KB |
Output is correct |
10 |
Correct |
58 ms |
348 KB |
Output is correct |
11 |
Correct |
55 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
69 ms |
484 KB |
Output is correct |
9 |
Correct |
87 ms |
348 KB |
Output is correct |
10 |
Correct |
58 ms |
348 KB |
Output is correct |
11 |
Correct |
55 ms |
348 KB |
Output is correct |
12 |
Execution timed out |
2101 ms |
5380 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |