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;
using ll = long long; 
const int N = 5e5 + 5; 
int n; 
int v[N << 1]; 
int a[N << 1], r[N << 1]; 
multiset<int> ms; 
int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n; 
    for(int i = 0; i < n; i++){
        cin >> v[i]; 
        v[i + n] = v[i]; 
    }
    for(int i = 1; i < 2 * n; i++){
        v[i] += v[i - 1]; 
    }
    auto get_sum = [&](int x) -> int{
        return v[x + (n - 1) / 2] - (x ? v[x - 1] : 0); 
    }; 
    for(int i = 0; i < n; i++){
        a[i] = r[i + (n + 1) / 2] = get_sum(i); 
    }
    int ans = 0; 
    for(int i = 0; i < 2 * n; i++){
        ms.insert(a[i]); 
        ms.extract(r[i]); 
        ans = max(ans, *ms.begin()); 
        // cout << a[i] << ' ' << r[i] << '\n'; 
    }
    cout << ans << '\n'; 
    return 0; 
}
| # | 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... |