#include<bits/stdc++.h>
const int N = 5e5 + 5;
using namespace std;
deque <int> mq;
int n, a[N], sum[2*N], maxx;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= (n+1)/2; i++) sum[1] += a[i];
for (int i = 2; i <= n; i++){
sum[2] = sum[1] + a[i-1+(n+1)/2] - a[i-1];
}
for (int i = 1; i <= n; i++){
sum[n+i] = sum[i];
}
for (int i = 1; i <= n; i++){
while(mq.size() && sum[mq.front()] > sum[i]) mq.pop_front();
mq.push_back(i);
if (i - mq.back() >= (n+1)/2) mq.pop_back();
maxx = max(sum[mq.back()], maxx);
}
cout << maxx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
8036 KB |
Output is correct |
2 |
Incorrect |
0 ms |
8036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
8036 KB |
Output is correct |
2 |
Incorrect |
0 ms |
8036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
8036 KB |
Output is correct |
2 |
Incorrect |
0 ms |
8036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
8036 KB |
Output is correct |
2 |
Incorrect |
0 ms |
8036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |