| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1329935 | Hduong | Hacker (BOI15_hac) | C++20 | 42 ms | 13120 KiB |
#include <bits/stdc++.h>
#define task "task"
using namespace std;
const long long INF = 1e18;
const int N = 5e5 + 5;
long long n, a[N], sum[N], res[N];
long long get_sum (int l, int r) {
long long res = 0;
if (l <= r) res = sum[r] - sum[l];
else res = sum[n] - sum[l] + sum[r];
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
if (n == 1) {
cout << a[1];
return 0;
}
long long siz = (n + 1) / 2;
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
for (int i = 0; i < n; i++) res[i] = get_sum(i, (i + siz) % n);
deque <int> q = {0};
long long ans = 0;
for (int i = 1; i < siz; i++) {
while(!q.empty() and res[i] < res[q.back()]) q.pop_back();
q.push_back(i);
}
// for (int i = 0; i < n; i++) cout << res[i] << " ";
for (int i = siz; i < siz + n; i++) {
ans = max(ans, res[q.front()]);
if ((i - siz) % n == q.front()) q.pop_front();
while (!q.empty() and res[i % n] < res[q.back()]) q.pop_back();
q.push_back(i % n);
}
cout << ans << "\n";
}
컴파일 시 표준 에러 (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... | ||||
