# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1057220 | juicy | Seesaw (JOI22_seesaw) | C++17 | 55 ms | 15568 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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n;
int a[N], fre[N];
long long pf[N];
double qry(int l, int r) {
return (double) (pf[r] - pf[l - 1]) / (r - l + 1);
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pf[i] = pf[i - 1] + a[i];
}
double A = qry(1, n);
vector<pair<double, int>> cands = {{A, n}};
for (int l = 1; l < n; ++l) {
int L = 1, R = n - l + 1, p = 0;
while (L <= R) {
int md = (L + R) / 2;
if (qry(md, md + l - 1) < A) {
p = md;
L = md + 1;
} else {
R = md - 1;
}
}
cands.push_back({qry(p, p + l - 1), l});
cands.push_back({qry(p + 1, p + l), l});
}
sort(cands.begin(), cands.end());
double res = 1e9;
for (int i = 0, j = 0, cnt = 0; i < cands.size(); ++i) {
while (j < cands.size() && cnt < n) {
cnt += !fre[cands[j++].second]++;
}
if (cnt == n) {
res = min(res, cands[j - 1].first - cands[i].first);
}
cnt -= !--fre[cands[i].second];
}
cout << fixed << setprecision(12) << res;
return 0;
}
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... |