#include<bits/stdc++.h> using namespace std; #define maxn 20005 long long pre,post,ans=0; int a[maxn],n; int main() { cin>>n; for(int i=0; i<n; i++) cin>>a[i]; int i=0,j=n-1; pre=a[0]; post=a[n-1]; while(i<j) { if(pre==post) { i++; j--; ans=max(ans,pre); pre+=a[i]; post+=a[j]; } else if(pre<post) { i++; pre+=a[i]; } else { j--; post+=a[j]; } } cout<<ans<<endl; return 0; }
C - Three Parts of the Array -(数组左-右搜索)
最新推荐文章于 2020-05-18 22:10:51 发布