题目链接:http://codeforces.com/contest/1006/problem/C
题意是给n个数字让分成三组(允许组里是空的),而且要第一组的和等于第三组的和,还有就是让第一组的和尽量大,输出最大的和。
思路就是模拟,挺简单的...
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
int n;
int pre[200005];
int main()
{
cin>>n;
for(int i=0;i<n;i++){
cin>>pre[i];
}
ll l = 0, r = n - 1, sl = pre[0], sr = pre[n-1];
ll ans = 0;
while(l < r){
if(sl == sr)
ans = max(ans,sr);
if(sl < sr){
sl += pre[++l];
}
else{
sr += pre[--r];
}
}
cout<<ans<<endl;
return 0;
}