이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |