#include<bits/stdc++.h>
using namespace std;
int kaf=(1<<19);
struct segment{
int seg[(1<<20)];
segment(){
for(int i=0;i<(1<<20);i++){
seg[i]=0;
}
}
void upd(int i,int l,int r,int tl,int tr,int w){
if(l>r||l>tr||r<tl){
return ;
}
if(l>=tl&&r<=tr){
seg[i]=max(seg[i],w);
return ;
}
int m=(l+r)>>1;
upd((i<<1),l,m,tl,tr,w);
upd((i<<1)^1,m+1,r,tl,tr,w);
return ;
}
int pors(int i){
if(i==0){
return 0;
}
int d=seg[i];
d=max(d,pors((i>>1)));
return d;
}
};
segment seg;
int n;
void add(int l,int r,int w){
if(r>l){
seg.upd(1,0,kaf-1,0,l-1,w);
seg.upd(1,0,kaf-1,r+1,n,w);
}
else{
seg.upd(1,0,kaf-1,r+1,l-1,w);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
vector<int>all(n);
int alls=0;
for(int i=0;i<n;i++){
cin>>all[i];
alls+=all[i];
}
int len=n/2;
int l=0,r=len-1;
int suma=0;
for(int j=0;j<len;j++){
suma+=all[j];
}
add(l,r,suma);
bool f=0;
while(l!=0||f==0){
f=1;
suma-=all[l];
l++;
l%=n;
r++;
r%=n;
suma+=all[r];
add(l,r,suma);
}
int mina=1e9+5;
for(int i=0;i<n;i++){
mina=min(mina,seg.pors(kaf+i));
// cout<<i<<" "<<mina<<"\n";
}
int res=alls-mina;
cout<<res<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
2 ms |
4412 KB |
Output is correct |
6 |
Correct |
2 ms |
4392 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4308 KB |
Output is correct |
10 |
Correct |
2 ms |
4308 KB |
Output is correct |
11 |
Correct |
3 ms |
4308 KB |
Output is correct |
12 |
Correct |
2 ms |
4308 KB |
Output is correct |
13 |
Correct |
2 ms |
4308 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
2 ms |
4376 KB |
Output is correct |
16 |
Correct |
2 ms |
4308 KB |
Output is correct |
17 |
Correct |
2 ms |
4344 KB |
Output is correct |
18 |
Correct |
2 ms |
4424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
2 ms |
4412 KB |
Output is correct |
6 |
Correct |
2 ms |
4392 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4308 KB |
Output is correct |
10 |
Correct |
2 ms |
4308 KB |
Output is correct |
11 |
Correct |
3 ms |
4308 KB |
Output is correct |
12 |
Correct |
2 ms |
4308 KB |
Output is correct |
13 |
Correct |
2 ms |
4308 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
2 ms |
4376 KB |
Output is correct |
16 |
Correct |
2 ms |
4308 KB |
Output is correct |
17 |
Correct |
2 ms |
4344 KB |
Output is correct |
18 |
Correct |
2 ms |
4424 KB |
Output is correct |
19 |
Correct |
2 ms |
4424 KB |
Output is correct |
20 |
Correct |
2 ms |
4420 KB |
Output is correct |
21 |
Correct |
2 ms |
4424 KB |
Output is correct |
22 |
Correct |
3 ms |
4440 KB |
Output is correct |
23 |
Correct |
4 ms |
4436 KB |
Output is correct |
24 |
Correct |
4 ms |
4452 KB |
Output is correct |
25 |
Correct |
4 ms |
4464 KB |
Output is correct |
26 |
Correct |
4 ms |
4436 KB |
Output is correct |
27 |
Correct |
2 ms |
4308 KB |
Output is correct |
28 |
Correct |
2 ms |
4308 KB |
Output is correct |
29 |
Correct |
2 ms |
4308 KB |
Output is correct |
30 |
Correct |
4 ms |
4436 KB |
Output is correct |
31 |
Correct |
4 ms |
4436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
4 ms |
4564 KB |
Output is correct |
4 |
Correct |
28 ms |
4948 KB |
Output is correct |
5 |
Correct |
66 ms |
5972 KB |
Output is correct |
6 |
Correct |
84 ms |
6212 KB |
Output is correct |
7 |
Correct |
101 ms |
6356 KB |
Output is correct |
8 |
Correct |
165 ms |
7048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
2 ms |
4412 KB |
Output is correct |
6 |
Correct |
2 ms |
4392 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4308 KB |
Output is correct |
10 |
Correct |
2 ms |
4308 KB |
Output is correct |
11 |
Correct |
3 ms |
4308 KB |
Output is correct |
12 |
Correct |
2 ms |
4308 KB |
Output is correct |
13 |
Correct |
2 ms |
4308 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
2 ms |
4376 KB |
Output is correct |
16 |
Correct |
2 ms |
4308 KB |
Output is correct |
17 |
Correct |
2 ms |
4344 KB |
Output is correct |
18 |
Correct |
2 ms |
4424 KB |
Output is correct |
19 |
Correct |
2 ms |
4424 KB |
Output is correct |
20 |
Correct |
2 ms |
4420 KB |
Output is correct |
21 |
Correct |
2 ms |
4424 KB |
Output is correct |
22 |
Correct |
3 ms |
4440 KB |
Output is correct |
23 |
Correct |
4 ms |
4436 KB |
Output is correct |
24 |
Correct |
4 ms |
4452 KB |
Output is correct |
25 |
Correct |
4 ms |
4464 KB |
Output is correct |
26 |
Correct |
4 ms |
4436 KB |
Output is correct |
27 |
Correct |
2 ms |
4308 KB |
Output is correct |
28 |
Correct |
2 ms |
4308 KB |
Output is correct |
29 |
Correct |
2 ms |
4308 KB |
Output is correct |
30 |
Correct |
4 ms |
4436 KB |
Output is correct |
31 |
Correct |
4 ms |
4436 KB |
Output is correct |
32 |
Correct |
2 ms |
4308 KB |
Output is correct |
33 |
Correct |
2 ms |
4308 KB |
Output is correct |
34 |
Correct |
4 ms |
4564 KB |
Output is correct |
35 |
Correct |
28 ms |
4948 KB |
Output is correct |
36 |
Correct |
66 ms |
5972 KB |
Output is correct |
37 |
Correct |
84 ms |
6212 KB |
Output is correct |
38 |
Correct |
101 ms |
6356 KB |
Output is correct |
39 |
Correct |
165 ms |
7048 KB |
Output is correct |
40 |
Correct |
6 ms |
4436 KB |
Output is correct |
41 |
Correct |
9 ms |
4564 KB |
Output is correct |
42 |
Correct |
12 ms |
4676 KB |
Output is correct |
43 |
Correct |
73 ms |
5896 KB |
Output is correct |
44 |
Correct |
170 ms |
7116 KB |
Output is correct |
45 |
Correct |
34 ms |
5076 KB |
Output is correct |
46 |
Correct |
101 ms |
6312 KB |
Output is correct |
47 |
Correct |
173 ms |
7020 KB |
Output is correct |
48 |
Correct |
189 ms |
7116 KB |
Output is correct |
49 |
Correct |
183 ms |
6896 KB |
Output is correct |
50 |
Correct |
169 ms |
7028 KB |
Output is correct |