이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Observations:
* Player takes ceil(n/2) computers, system takes floor(n/2) computers.
* Computers taken by either the player or the system form a subarray.
* After the player choose the first computer, the system can control which computers will end up for the player.
The system can do so by "copying" player's move.
With the above observation, we will take the maximum of the minimum sum of values in a segment involving the i-th computer.
*/
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, a[1000003], psum[1000003], ans;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i + n] = a[i];
}
psum[0] = a[0];
for (int i = 1; i < 2 * n; i++) {
psum[i] = psum[i - 1] + a[i];
}
int cntTakenByPlayer = n/2 + n%2;
multiset<int> segmentSums;
ans = 0;
for (int i = 0; i + cntTakenByPlayer - 1 < n; i++) {
segmentSums.insert(psum[i + cntTakenByPlayer - 1] - (i == 0 ? 0 : psum[i - 1]));
if (i >= cntTakenByPlayer) {
int sumEndingAtPreviousIdx = psum[i - 1] - (i - 1 - cntTakenByPlayer >= 0 ? psum[i - 1 - cntTakenByPlayer] : 0);
segmentSums.erase(segmentSums.find(sumEndingAtPreviousIdx));
}
ans = max(ans, *(segmentSums.begin()));
}
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... |