提交时间:2023-08-09 17:36:19
运行 ID: 81642
#include<bits/stdc++.h> using namespace std; long long cake[100010],n,a,b,c,d,ans=0; long long bind,cind,dind; int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>cake[i]; } for(int i=0;i<n-2;i++){ a+=cake[i]; } bind=n-2; cind=n-1; dind=n; b=cake[n-2]; c=cake[n-1]; d=0; // cout<<a<<endl; if(ans<min(min(a+d,b),c)) ans=min(min(a+d,b),c); while(a>0){ bind--; b+=cake[bind]; a-=cake[bind]; if(a<0) break; long long tb=b; // int tbind=bind; cind=n-1; dind=n; c=cake[n-1]; d=0; if(ans<min(min(a+d,b),c)) ans=min(min(a+d,b),c); while(tb>0){ cind--; c+=cake[cind]; tb-=cake[cind]; if(tb<0) break; long long tc=c; dind=n; d=0; if(ans<min(min(a+d,tb),c)) ans=min(min(a+d,tb),c); // if(min(min(a+d,tb),c)==7){ // cout<<bind<<" "<<cind<<" "<<dind<<" "; // cout<<a<<" "<<tb<<" "<<c<<" "<<d; // } while(tc>0){ dind--; d+=cake[dind]; tc-=cake[dind]; if(tc<0) break; if(ans<min(min(a+d,tb),tc)) ans=min(min(a+d,tb),tc); // cout<<min(min(a+d,tb),tc)<<endl; } } } cout<<ans; return 0; }