#include <iostream>
using namespace std;
const int N=2e5;
int suf[N],pre[N],d[N];
int n;
int res;
int main()
{
cin>>n;
pre[0]=0;
for(int i=1;i<=n;i++)
cin>>d[i];
for(int i=1;i<=n;i++)
{ pre[i]=pre[i-1]+d[i];}
suf[n]=d[n];
for(int i=n-1;i>0;i--)
{
suf[i]=suf[i+1]+d[i];
}
for(int i=1;i<=n;i++)
{
int x=lower_bound(pre+1,pre+1+n,suf[i])-pre;
if(x<i&&suf[i]==pre[x])
res=max(res,suf[i]);
}
cout<<res;
return 0;
}
习题练习 Three Parts of the Array(二分+前缀和)
最新推荐文章于 2024-08-14 20:03:33 发布