Submission #1191921

#TimeUsernameProblemLanguageResultExecution timeMemory
1191921heheHacker (BOI15_hac)C++20
40 / 100
1095 ms1568 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MAXN = 5e5 + 2;

int n;
int a[MAXN], sums[MAXN];

signed main() {
    cin >> n;
    
    int sum = 0;
    int half = (n + 1) / 2;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i < half) {
            sum += a[i];
        }
    }

    for (int i = 0; i <= n; i++) {
        sums[i % n] = sum;
        sum += a[(i + half) % n];
        sum -= a[i % n];
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int L = (i - half + 1 + n) % n;
        int R = i;
        
        int min_val = LLONG_MAX;
        if (R >= L) {
            for (int j = L; j <= R; j++) {
                min_val = min(min_val, sums[j]);
            }
        } else {
            for (int j = L; j < n; j++) {
                min_val = min(min_val, sums[j]);
            }
            for (int j = 0; j <= R; j++) {
                min_val = min(min_val, sums[j]);
            }
        }
        
        ans = max(ans, min_val);
    }

    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...