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;
const int N = 500005;
int n, s[N], a[N], f[N], rmq[20][N], lg[N];
int gets(int l, int r) {
return s[r] - s[l - 1];
}
int getm(int l, int r) {
if (l > r) return 1e9;
int k = lg[r - l + 1];
return min(rmq[k][l], rmq[k][r - (1 << k) + 1]);
}
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
for (int i = 1; i <= n; ++i) {
cin >> a[i], s[i] += s[i - 1] + a[i];
}
int val = (n + 1) / 2;
for (int i = 1; i <= n; ++i) {
rmq[0][i] = f[i] = gets(i, min(n, i + val - 1)) + gets(1, max(0, (i + val - 1) - n));
}
for (int i = 1; i < 20; ++i) {
for (int j = 1; j + (1 << i) - 1 <= n; ++j) {
rmq[i][j] = min(rmq[i - 1][j], rmq[i - 1][j + (1 << (i - 1))]);
}
}
int res = 0;
for (int i = 1; i <= n; ++i) {
int tmp = min(getm(max(1, i - val + 1), i), getm(n - max(0, val - i) + 1, n));
res = max(res, tmp);
}
cout << res;
}
# | 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... |