#include <bits/stdc++.h>
using namespace std;
#define double long double
const int N = 2'000 + 10;
const double MAX = 1e9;
int n;
int a[N];
long long pref[N];
inline long long sum(int l, int r) { return pref[r] - pref[l - 1]; }
inline double cal(int l, int r) { return (double)sum(l, r) / (r - l + 1); }
int way[N][N];
pair<int, int> par[N][N];
bool mk[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];
using TP = tuple<double, int, int>;
priority_queue<TP, vector<TP>, greater<>> q;
multiset<double> s;
double answer = MAX;
auto go = [&](int x, int y) {
if (!x && !y) return;
while (x != y) {
if (!mk[x][y]) s.insert(cal(x, y)), q.emplace(cal(x, y), x, y), mk[x][y] = true;
int nX = (!way[x][y] ? x : x + 1), nY = (!way[x][y] ? y - 1 : y);
par[nX][nY] = {x, y};
tie(x, y) = {nX, nY};
if (mk[x][y]) break;
}
if (!mk[x][y]) s.insert(cal(x, y)), q.emplace(cal(x, y), x, y), mk[x][y] = true;
answer = min(answer, *s.rbegin() - *s.begin());
};
go(1, n);
while (q.size()) {
auto [d, i, j] = q.top(); q.pop();
if (i != 1 || j != n) s.extract(d);
auto [x, y] = par[i][j];
if (way[x][y]) continue;
way[x][y] = 1;
go(x, y);
}
cout << setprecision(9) << fixed << answer << "\n";
cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\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... |