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 main() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(12);
int N;
cin >> N;
vector<int> A(N);
for (int &value : A) {
cin >> value;
}
vector<long long> pref(N + 1);
for (int i = 0; i < N; i++) {
pref[i + 1] = pref[i] + A[i];
}
auto Mean = [&](int L, int R) { return 1.L * (pref[R] - pref[L]) / (R - L); };
vector<array<int, 2>> seg = {{0, N}};
for (int len = 1; len < N; len++) {
int low = -1, high = N - len + 1;
while (high - low > 1) {
int mid = (low + high) / 2;
if (Mean(mid, mid + len) <= Mean(0, N)) {
low = mid;
} else {
high = mid;
}
}
if (low >= 0) {
seg.push_back({low, low + len});
}
if (high + len <= N) {
seg.push_back({high, high + len});
}
}
sort(seg.begin(), seg.end(), [&](array<int, 2> x, array<int, 2> y) {
return Mean(x[0], x[1]) < Mean(y[0], y[1]);
});
vector<int> cnt(N + 1);
int bad_count = N;
long double result = numeric_limits<long double>::max();
for (int i = 0, j = 0; i < int(seg.size()); i++) {
while (j < int(seg.size()) && bad_count > 0) {
bad_count -= cnt[seg[j][1] - seg[j][0]]++ == 0;
j++;
}
if (bad_count == 0) {
result = min(result, Mean(seg[j - 1][0], seg[j - 1][1]) - Mean(seg[i][0], seg[i][1]));
}
bad_count += --cnt[seg[i][1] - seg[i][0]] == 0;
}
cout << result << "\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... |