# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
791796 | lovrot | Hacker (BOI15_hac) | C++17 | 54 ms | 8140 KiB |
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 <cstdio>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
const int oo = 2e9 + 10;
int n, V[N];
char B[N];
int S[N];
deque<int> Q;
void add(int x, deque<int> &A) {
while(!A.empty() && A.back() > x) A.pop_back();
A.push_back(x);
}
void pop(int x, deque<int> &A) {
if(!A.empty() && A.front() == x) A.pop_front();
}
int get(deque<int> &A) {
return A.empty() ? -1 : A.front();
}
int main() {
scanf("%d", &n);
int sum = 0, _sum = 0;
for(int i = 0; i < n; ++i) {
scanf("%d", V + i);
sum += V[i];
if(i < n / 2) _sum += V[i];
}
for(int i = n / 2 - 1; B[i] == 0;) {
S[i] = sum - _sum;
B[i] = 1;
i = (i + 1) % n;
_sum += V[i];
_sum -= V[(i - n / 2 + n) % n];
}
for(int i = n / 2 - 1; i < n - 1; ++i) add(S[i], Q);
int ans = -oo;
for(int i = n - 1; B[i] != 2;) {
ans = max(ans, get(Q));
B[i] = 2;
pop(S[(i - (n + 1) / 2 + n) % n], Q);
i = (i + 1) % n;
add(S[(i - 1 + n) % n], Q);
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | 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... |