This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int ll
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
using namespace std;
const int N = 200 + 10, mod = 1e9 + 7;
int n;
double a[N], pref[N];
double solve(int l, int r, double cur, double mi, double mx) {
if(l == r) {
mi = min(cur, mi);
mx = max(cur, mx);
return abs(mx - mi);
}
double c1 = 0, c2 = 0;
if(l < n) c1 = solve(l + 1, r, double(double(pref[r] - pref[l])/double(r-l)), min(mi, cur), max(mx, cur));
if(r > 1) c2 = solve(l, r - 1, double(double(pref[r-1] - pref[l-1])/double(r-l)), min(mi, cur), max(mx, cur));
return min(c1, c2);
}
signed main()
{
FAST;
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
pref[1] = a[1];
for(int i = 2; i <= n; i++) pref[i] += a[i] + pref[i-1];
cout << solve(1, n, double(pref[n]/n), double(pref[n]/n), double(pref[n]/n)) << endl;
}
# | 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... |