Submission #1118651

#TimeUsernameProblemLanguageResultExecution timeMemory
1118651orcslopHacker (BOI15_hac)C++17
100 / 100
228 ms34192 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
#define f first
#define s second
#define pii pair<int, int>

const int N = 5e5 + 5; 

int n; 
int v[N << 1]; 
multiset<int> ms; 
priority_queue<pii, vector<pii>, greater<pii>> pq; 

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++){
        ms.insert(i); 
        pq.push({get_sum(i), i}); 
    }
    int ans = 0; 
    while(!pq.empty()){
        if(ms.size()) ans = pq.top().f; 
        else break; 
        auto x = pq.top().s, d = (n + 1) / 2; 
        pq.pop(); 
        while(d){
            auto it = ms.lower_bound(x); 
            while(it != ms.end() && *it <= x + d - 1) {
                ms.erase(it); 
                it = ms.lower_bound(x); 
            }
            d = max(0, x + d - n); 
            x = 0; 
        }
    }
    cout << ans << '\n'; 
    return 0; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...