#include <bits/stdc++.h>
using namespace std;
#define double long double
const int N = 2'000 + 10;
int n;
int a[N];
long long pref[N];
inline long long sum(int l, int r) { return pref[r] - pref[l - 1]; }
int way[N][N];
double f[N][N];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i];
double answer = 1e9;
for (int l = 1; l <= n; ++l) {
for (int r = l; r <= n; ++r) {
double mi = (double)sum(l, r) / (r - l + 1);
{ // clear
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) f[i][j] = 1e9;
}
}
f[1][n] = (double)sum(1, n) / n;
for (int i = 1; i <= n; ++i) {
for (int j = n; j > i; --j) {
if ((double)sum(i, j) / (j - i + 1) < mi || f[i][j] == 1e9) continue;
f[i][j] = max(f[i][j], (double)sum(i, j) / (j - i + 1));
f[i + 1][j] = min(f[i + 1][j], f[i][j]);
f[i][j - 1] = min(f[i][j - 1], f[i][j]);
}
}
for (int i = 1; i <= n; ++i) {
if ((double)sum(i, i) / (i - i + 1) < mi || f[i][i] == 1e9) continue;
f[i][i] = max(f[i][i], (double)sum(i, i) / (i - i + 1));
answer = min(answer, f[i][i] - mi);
}
}
}
cout << setprecision(9) << fixed << answer << "\n";
}
# | 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... |