This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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));
}
chmin(ans, mx - mi);
}
cout << setprecision(9) << fixed;
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |