/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#include <iostream>
using namespace std;
int const N=5e5+10;
int St[4*N]={};
int pre[N]={};
int n;
void update(int i,int r,int st,int en,int val)
{
if (st==en)
{
St[i]=val;
return;
}
int mid=(st+en)/2;
if (r<=mid)
update(i*2,r,st,mid,val);
else
update(i*2+1,r,mid+1,en,val);
St[i]=max(St[i*2],St[i*2+1]);
}
int get(int i,int st,int en,int l,int r)
{
if (st>r||en<l)
return 0;
if (st>=l&&en<=r)
return St[i];
int mid=(st+en)/2;
return (max(get(i*2,st,mid,l,r),get(i*2+1,mid+1,en,l,r)));
}
inline void solve()
{
cin>>n;
int a[n];
for (auto& i:a)
cin>>i;
for (int i=0;i<n;i++)
pre[i+1]=pre[i]+a[i];
int ans=0;
for (int i=0;i<n;i++)
{
if (i+n/2>n)
{
int z=pre[n]-pre[i];
int f=i+n/2-n;
z+=pre[f];
update(1,i,0,n-1,z);
}
else
{
int z=pre[i+n/2]-pre[i];
update(1,i,0,n-1,z);
}
}
for (int i=0;i<n;i++)
{
int f=i-n/2;
f=(f+n)%n;
int g=i+1;
if (g<f)
ans=max(ans,pre[n]-get(1,0,n-1,g,f));
else
{
int z=max(get(1,0,n-1,g,n-1),get(1,0,n-1,0,f));
ans=max(ans,pre[n]-z);
}
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2512 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2488 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2512 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2512 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2488 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2512 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2392 KB |
Output is correct |
23 |
Correct |
2 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
2 ms |
2392 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
30 ms |
5404 KB |
Output is correct |
5 |
Correct |
74 ms |
6236 KB |
Output is correct |
6 |
Correct |
95 ms |
6744 KB |
Output is correct |
7 |
Correct |
114 ms |
9324 KB |
Output is correct |
8 |
Correct |
197 ms |
10920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2512 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2488 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2512 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2392 KB |
Output is correct |
23 |
Correct |
2 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
2 ms |
2392 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2396 KB |
Output is correct |
35 |
Correct |
30 ms |
5404 KB |
Output is correct |
36 |
Correct |
74 ms |
6236 KB |
Output is correct |
37 |
Correct |
95 ms |
6744 KB |
Output is correct |
38 |
Correct |
114 ms |
9324 KB |
Output is correct |
39 |
Correct |
197 ms |
10920 KB |
Output is correct |
40 |
Correct |
4 ms |
2392 KB |
Output is correct |
41 |
Correct |
8 ms |
2652 KB |
Output is correct |
42 |
Correct |
11 ms |
2652 KB |
Output is correct |
43 |
Correct |
86 ms |
6236 KB |
Output is correct |
44 |
Correct |
211 ms |
10916 KB |
Output is correct |
45 |
Correct |
39 ms |
5468 KB |
Output is correct |
46 |
Correct |
124 ms |
9164 KB |
Output is correct |
47 |
Correct |
195 ms |
10912 KB |
Output is correct |
48 |
Correct |
196 ms |
11356 KB |
Output is correct |
49 |
Correct |
191 ms |
10068 KB |
Output is correct |
50 |
Correct |
194 ms |
10316 KB |
Output is correct |