题目链接:http://codeforces.com/contest/1006/problem/C
题意:
把一个数组分成L, MID, R三段, 每段都可以为空,求可以使SUML = SUMR 的最大SUML值。
代码:
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
const int maxn = 2e5 + 7;
ll a[maxn];
int main()
{
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i];
ll res = 0;
int L = 1, R = n;
ll lsum = a[1], rsum = a[n];
while(L < R) {
if(lsum == rsum) {
res = max(res, lsum);
L ++;
R --;
lsum += a[L];
rsum += a[R];
} else if(lsum > rsum) {
R --;
rsum += a[R];
} else {
L ++;
lsum += a[L];
}
}
cout << res << '\n';
return 0;
}