# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
871009 | Trisanu_Das | Seesaw (JOI22_seesaw) | C++17 | 2041 ms | 4712 KiB |
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>
using namespace std;
int A[200005], n;
long long pref[200005];
long double ans;
long double calc(int l, int r) {
return (long double)(pref[r] - pref[l - 1]) / (r - l + 1);
}
long double solve(long double max_r) {
int l = 1, r = n;
long double tl = calc(l, r), tr = calc(l, r);
while (l < r) {
long double tll = min(tl, calc(l + 1, r)), tlr = max(tr, calc(l + 1, r));
if (tlr <= max_r) l++;
else r--;
tl = min(tl, calc(l, r));
tr = max(tr, calc(l, r));
if (tr - tl >= ans) return tr - tl;
}
return tr - tl;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i];
pref[i] = pref[i - 1] + A[i];
}
ans = A[n] - A[1];
for (int l = 1; l <= n; l++) for (int r = l; r <= n; r++) ans = min(ans, solve(calc(l, r)));
cout << setprecision(10) << fixed << ans << '\n';
}
Compilation message (stderr)
# | 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... |