#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]=0x3f3f3f3f;
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 0x3f3f3f3f;
}
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);
resp=max(resp, u);
}
cout << resp << endl;
}
# |
Verdict |
Execution time |
Memory |
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 |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
640 KB |
Output is correct |
24 |
Correct |
8 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
7 ms |
640 KB |
Output is correct |
4 |
Correct |
44 ms |
3532 KB |
Output is correct |
5 |
Correct |
119 ms |
7132 KB |
Output is correct |
6 |
Correct |
181 ms |
8056 KB |
Output is correct |
7 |
Correct |
157 ms |
12920 KB |
Output is correct |
8 |
Correct |
267 ms |
15608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
640 KB |
Output is correct |
24 |
Correct |
8 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
3 ms |
384 KB |
Output is correct |
34 |
Correct |
7 ms |
640 KB |
Output is correct |
35 |
Correct |
44 ms |
3532 KB |
Output is correct |
36 |
Correct |
119 ms |
7132 KB |
Output is correct |
37 |
Correct |
181 ms |
8056 KB |
Output is correct |
38 |
Correct |
157 ms |
12920 KB |
Output is correct |
39 |
Correct |
267 ms |
15608 KB |
Output is correct |
40 |
Correct |
8 ms |
768 KB |
Output is correct |
41 |
Correct |
12 ms |
1140 KB |
Output is correct |
42 |
Correct |
16 ms |
1280 KB |
Output is correct |
43 |
Correct |
112 ms |
7416 KB |
Output is correct |
44 |
Correct |
274 ms |
15608 KB |
Output is correct |
45 |
Correct |
50 ms |
3704 KB |
Output is correct |
46 |
Correct |
172 ms |
12932 KB |
Output is correct |
47 |
Correct |
308 ms |
15636 KB |
Output is correct |
48 |
Correct |
328 ms |
16056 KB |
Output is correct |
49 |
Correct |
299 ms |
15076 KB |
Output is correct |
50 |
Correct |
270 ms |
15072 KB |
Output is correct |