Submission #1248067

#TimeUsernameProblemLanguageResultExecution timeMemory
1248067chikien2009Hacker (BOI15_hac)C++20
100 / 100
75 ms28572 KiB
#include <bits/stdc++.h>

using namespace std;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n, a[1000001];
long long pre[1000001], res;
priority_queue<pair<long long, int>> pq;

int main()
{
    setup();

    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        a[i + n] = a[i];
    }
    for (int i = 1; i <= 2 * n; ++i)
    {
        pre[i] = a[i] + pre[i - 1];
    }
    for (int i = 1, j = 1; i <= n; ++i)
    {
        while (j + n / 2 < i + n)
        {
            pq.push({pre[j + n / 2] - pre[j], j});
            j++;
        }
        while (!pq.empty() && pq.top().second < i)
        {
            pq.pop();
        }
        res = max(res, pre[n] - pq.top().first);
    }
    cout << res;
    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...