题解
2024-10-13 12:54:28
发布于:浙江
1阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int n,a[114514],ans = 0;
int main(){
cin >> n;
for(int i = 0;i < n;i ++){
cin >> a[i];
ans += a[i];
}
int son1 = a[0],son2 = a[n - 1];
int l = 0,r = n - 1;
int cur = ans - son1 - son2;
if(son1 == son2) ans = cur;
while(l < r){
if(son1 == son2) {
ans = cur;
l ++;
son1 += a[l];
cur -= a[l];
}
while(l < r && son1 < son2){
l ++;
son1 += a[l];
cur -= a[l];
}
while(l < r && son1 > son2){
r --;
son2 += a[r];
cur -= a[r];
}
}
cout << ans << endl;
return 0;
}
这里空空如也
有帮助,赞一个