이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Source: https://oj.uz/problem/view/BOI15_hac
//
#include "bits/stdc++.h"
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<int> vi;
#define FOR(i, a, b) for (int i = (a); i<b; i++)
bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }
bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }
const int N = 5e5 + 10;
int a[N];
int res[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
FOR(i, 0, n) cin >> a[i];
int sum = 0;
FOR(i, 0, (n+1)/2) sum += a[i];
int i = 0;
int j = (n+1)/2;
for (;i < n;) {
res[i] = sum;
sum += a[j]-a[i];
i++;
j = (j + 1) % n;
}
multiset<int> window;
FOR(i, 0, (n + 1) / 2) window.insert(res[i]);
int ans = 0;
i = 0;
j = (n+1)/2;
for (;i < n;) {
ans = max(ans, *window.begin());
window.erase(window.find(res[i]));
window.insert(res[j]);
i++;
j = (j + 1) % n;
}
cout << ans << endl;
}
| # | 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... |