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>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);
int n;
int a[1500005];
ll pref[1500005];
deque<int> d;
void ubaci(int x) {
while (d.size() > 0 && d.back() > x) d.pop_back();
d.push_back(x);
}
void izbaci(int x) {
if (d.size() > 0 && d.front() == x) d.pop_front();
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i+n] = a[i];
a[i+2*n] = a[i];
}
for (int i = 1; i <= 3*n; i++) pref[i] = pref[i-1] + a[i];
for (int i = n; i-(n+1)/2+1 <= n; i++) ubaci(pref[i]-pref[i-(n+1)/2]);
int sol = d.front();
for (int i = n+1; i <= 2*n; i++) {
izbaci(pref[i-1]-pref[i-1-(n+1)/2]);
ubaci(pref[i+(n+1)/2-1]-pref[i-1]);
sol = max(sol, d.front());
}
cout << sol;
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... |