#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2*(5e5+10);
int vet[MAXN], v[MAXN], tree[4*MAXN];
void build(int node, int l, int r){
if(l==r){
tree[node]=v[l];
if(v[l]==0)tree[node]=3000;
return;
}
int mid = (l+r)>>1;
build(2*node, l, mid);
build(2*node+1, mid+1, r);
tree[node] = min(tree[2*node], tree[2*node+1]);
}
int query(int node, int tl, int tr, int l, int r){
if(tr<l or tl>r){
return 3000;
}
if(tl>=l and tr<=r){
return tree[node];
}
int mid = (tl+tr)>>1;
int op1 = query(2*node, tl, mid, l, r);
int op2 = query(2*node+1, mid+1, tr, l, r);
return min(op1, op2);
}
int main(){
int n, k, resp=0;
cin >> n;
k = ceil((double)n/2);
for(int i=1; i<=n; i++){
cin >> vet[i];
}
build(1, 1, n);
int sum=0;
for(int i=n-k+2; ;i++){
if(i==2)break;
if(i==n+1)i=1;
sum+=vet[i];
}
v[1]=sum;
for(int i=n-k+3, q=2; q<=n+k-1; i++, q++){
int j=q;
if(i==n+1)i=1;
if(j>n)j-=n;
int a = i;
int b = j;
if(a==1)a=n+1;
if(b==n+1)b=1;
sum-=vet[a-1];
sum+=vet[b];
v[q]=sum;
}
build(1, 1, 2*n);
for(int i=1, j=k; i<=n; i++, j++){
int u = query(1, 1, 2*n, i, j);
if(u==3000)u=0;
resp=max(resp, u);
}
cout << resp << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |