提交时间:2023-08-09 20:18:47
运行 ID: 81684
#include<bits/stdc++.h> #define i64 long long using namespace std; i64 n,a[200010],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<=n+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; } ans=max(ans,min(min(sum(i,l),sum(l+1,tl)),sum(tl+1,j))); } cout<<ans; return 0; }