提交时间:2023-08-09 17:40:54

运行 ID: 81647

#include<bits/stdc++.h> using namespace std; #define int unsigned long long int n; int a[300010],pre[300010],ans=0; int min(int a,int b){ return ((a<=b)?a:b); } int max(int a,int b){ return ((a>=b)?a:b); } signed main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; a[i+n]=a[i]; } for(int i=1;i<=2*n;i++){ pre[i]=pre[i-1]+a[i]; } for(int i=1;i<=n;i++){ for(int x=i;x<=i+n-1;x++){ for(int y=x;y<=i+n-1;y++){ if(x<y-1) ans=max(ans,min(pre[x]-pre[i-1],min(pre[i+n-1]-pre[y-1],pre[y-1]-pre[x]))); } } } cout<<ans; return 0; }