| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 31597 | minhtung0404 | Hacker (BOI15_hac) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
const int N = 5e5 + 5;
using namespace std;
deque <long long> mq;
long long n, a[2*N], sum[2*N], maxx, siz;
int main(){
cin >> n;
siz = (n+1)/2;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= 2*n; i++) a[i] = a[i-1] + a[i];
for (int i = sz; i <= 2*n; i++) sum[i] = a[i] - a[i-sz];
for (int i = 1; i <= 2*n; i++){
while(mq.size() && sum[mq.front()] >= sum[i]) mq.pop_front();
mq.push_front(i);
if (i - mq.back() == siz) mq.pop_back();
if (i >= sz) maxx = max(sum[mq.back()], maxx);
}
cout << maxx;
}
