This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define forw(i,a,b) for(int i=a;i<=b;i++)
#define forb(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define getbit(mask,i) ((mask>>i)&1)
#define getnum(i) (1<<(i))
#define maxi(a,b) (a)=max((a),(b))
typedef long long int ll;
const ll maxN=3e5+5;
const ll mod=1e9+7;
const ll oo=1e18;
ll n,len,sum,a[maxN],pre[maxN],ans[maxN],suf[maxN],out;
void solve()
{
cin>>n;
len=n/2;
forw(i,1,n)
{
cin>>a[i];
a[i+n]=a[i];
sum+=a[i];
}
forw(i,1,2*n)
pre[i]=pre[i-1]+a[i];
forb(i,n,1)
{
ans[i]=pre[i+len-1]-pre[i-1];
suf[i]=max(suf[i+1],ans[i]);
}
ll tmp=0;
forw(i,1,n)
{
if (i-len>=1) tmp=max(tmp,ans[i-len]);
out=max(out,sum-max(tmp,suf[i+1]));
}
cout<<out;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("bruh.inp","r",stdin);
//freopen("bruh.out","w",stdout);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |