이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn 1050000
ii n, v[maxn], r[maxn], ps[maxn];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
//freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
cin >> n;
for(ii i = 1; i <= n; i++) {
cin >> v[i];
v[i+n] = v[i];
}
for(ii i = 1; i <= 2*n; i++) {
ps[i] = ps[i-1] + v[i];
r[i] = INFii;
}
ii ans = 0;
ii sz = (n+1)/2;
//cout << sz << endl;
priority_queue<pair<ii,ii>> pq;
for(ii i = 1; i <= 2*n; i++) {
if(i+sz-1 <= 2*n) pq.push(mp(-(ps[i+sz-1]-ps[i-1]),i));
while(pq.size() && pq.top().sc <= i-sz) pq.pop();
r[i] = -pq.top().fr;
}
for(ii i = 1; i <= n; i++) {
ans = max(ans, min(r[i],r[i+n]));
//cout << i << " " << min(r[i],r[i+n]) << endl;
}
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... |