#include <bits/stdc++.h>
using namespace std;
const int N = 200'000 + 10;
int n;
int a[N];
namespace sub1 {
bool checkCondition() { return n <= 20; }
int pref[N];
long double answer;
void recursion(int l, int r, long double mi, long double ma) {
if (l == r) {
answer = min(answer, ma - mi);
return;
}
{ // left
long double nMid = (long double) (pref[r] - pref[l]) / (r - l);
recursion(l + 1, r, min(mi, nMid), max(ma, nMid));
}
{ // right
long double nMid = (long double) (pref[r - 1] - pref[l - 1]) / (r - l);
recursion(l, r - 1, min(mi, nMid), max(ma, nMid));
}
}
void solve() {
for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i];
long double mid = (long double) pref[n] / n;
answer = 1e9;
recursion(1, n, mid, mid);
cout << setprecision(10) << fixed << answer << "\n";
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
if (sub1::checkCondition()) { sub1::solve(); 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... |