#include "bits/stdc++.h"
using namespace std;
#define INF 2000000000
#define INFLL 3000000000000000000LL
#define ll long long
struct segtree{
vector<ll>tree;
int size=1;
void init(int n){
while(size<n)size<<=1;
tree.assign(size*2-1, 0);
}
void update(int i, ll val, int x, int lx, int rx){
if(rx-lx==1)tree[x]=val;
else{
int mid=(lx+rx)/2;
if(i<mid)update(i,val, x*2+1,lx,mid);
else update(i,val, x*2+2,mid,rx);
tree[x]=max(tree[x*2+1],tree[x*2+2]);
}
}
void update(int i, ll val){
update(i,val, 0,0,size);
//for(int i=size-1;i<size*2-1;i++)cout<<tree[i]<<' ';
//cout<<"\n";
}
ll get(int ql, int qr, int x, int lx, int rx){
if(ql>=rx||lx>=qr)return 0;
if(ql<=lx&&rx<=qr)return tree[x];
else{
int mid=(lx+rx)/2;
return max(get(ql,qr, x*2+1,lx,mid),get(ql,qr, x*2+2,mid,rx));
}
}
ll get(int ql,int qr){
if(ql>=qr)return 0;
return get(ql,qr,0,0,size);
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin>>n;
ll arr[n];
ll sum=0;
ll sum2=0;
for(int i=0;i<n;i++){
cin>>arr[i];
sum+=arr[i];
if(i<n/2)sum2+=arr[i];
}
segtree seg;
seg.init(n);
for(int i=0;i<n;i++){
seg.update(i,sum2);
sum2-=arr[i];
sum2+=arr[(i+n/2)%n];
}
ll mx=0;
for(int i=0;i<n;i++){
ll sum2=max(seg.get(0,i-n/2+1),seg.get(i+1,i+(n+1)/2+1));
//cout<<sum2<<"\n";
ll mn=sum-sum2;
mx=max(mx,mn);
}
cout<<mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
32 ms |
2900 KB |
Output is correct |
5 |
Correct |
96 ms |
5976 KB |
Output is correct |
6 |
Correct |
93 ms |
6364 KB |
Output is correct |
7 |
Correct |
123 ms |
10856 KB |
Output is correct |
8 |
Correct |
188 ms |
12404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
32 ms |
2900 KB |
Output is correct |
36 |
Correct |
96 ms |
5976 KB |
Output is correct |
37 |
Correct |
93 ms |
6364 KB |
Output is correct |
38 |
Correct |
123 ms |
10856 KB |
Output is correct |
39 |
Correct |
188 ms |
12404 KB |
Output is correct |
40 |
Correct |
4 ms |
596 KB |
Output is correct |
41 |
Correct |
9 ms |
980 KB |
Output is correct |
42 |
Correct |
11 ms |
980 KB |
Output is correct |
43 |
Correct |
96 ms |
5972 KB |
Output is correct |
44 |
Correct |
187 ms |
12364 KB |
Output is correct |
45 |
Correct |
37 ms |
3156 KB |
Output is correct |
46 |
Correct |
128 ms |
10868 KB |
Output is correct |
47 |
Correct |
200 ms |
12412 KB |
Output is correct |
48 |
Correct |
185 ms |
12364 KB |
Output is correct |
49 |
Correct |
186 ms |
12428 KB |
Output is correct |
50 |
Correct |
201 ms |
12364 KB |
Output is correct |