이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define f first
#define s second
#define pii pair<int, int>
const int N = 5e5 + 5;
int n;
int v[N << 1];
multiset<int> ms;
priority_queue<pii, vector<pii>, greater<pii>> pq;
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 0; i < n; i++){
cin >> v[i];
v[i + n] = v[i];
}
for(int i = 1; i < 2 * n; i++){
v[i] += v[i - 1];
}
auto get_sum = [&](int x) -> int{
return v[x + (n - 1) / 2] - (x ? v[x - 1] : 0);
};
for(int i = 0; i < n; i++){
ms.insert(i);
pq.push({get_sum(i), i});
}
int ans = 0;
while(!pq.empty()){
if(!ms.size()) break;
ans = pq.top().f;
int x = pq.top().s;
int d = (n + 1) / 2;
pq.pop();
while(d){
auto it = ms.lower_bound(x);
while(it != ms.end() && *it < x + d) {
ms.erase(it);
it = ms.lower_bound(x);
}
d = max(0, x + d - n);
x = 0;
}
}
cout << ans << '\n';
return 0;
}
# | 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... |