提交时间:2023-08-09 23:53:04

运行 ID: 81700

#include<bits/stdc++.h> using namespace std; using i64=long long; int n,a[200010]; i64 ans,s[200010]; i64 sum(int l,int r){ return s[r]-s[l-1]; } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; a[n+i]=a[i]; } for(int i=1;i<=2*n;i++){ s[i]=s[i-1]+a[i]; } for(int i=1;i<=n;i++){ int j=i+n-1; int l=i,r=j; while(l<r){ int mid=(l+r+1)/2; if(3*sum(i,mid)>sum(1,n)){ r=mid-1; } else{ l=mid; } } int tl=l+1,tr=j; while(tl<tr){ int mid=(tl+tr)/2; if(3*sum(l+1,mid)<sum(1,n)){ tl=mid+1; } else{ tr=mid; } } i64 a=sum(i,l); i64 b=sum(l+1,tl); i64 c=sum(tl+1,j); ans=max(ans,min({a,b,c})); } cout<<ans; return 0; }