Submission #31573

#TimeUsernameProblemLanguageResultExecution timeMemory
31573aomeHacker (BOI15_hac)C++14
100 / 100
86 ms49052 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...