自己看
2026-08-17 11:04:34
发布于:广东
2阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t,n,a[200010],s[200010],s2[200010];
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=n;i++){
cin>>a[i];
}
for(ll i=1;i<=n;i++){
s[i]=s[i-1]+a[i];
}
s2[n+1]=0;
for(ll i=n;i>=1;i--) s2[i]=s2[i+1]+a[i];
ll l=1,r=n,ans=0;
while(l<r){
if(s[l]==s2[r]){
ans=l+(n-r+1);
l++;
r--;
}
else if(s[l]<s2[r]) l++;
else r--;
}
cout<<ans<<endl;
}
//fclose(stdin);
//fclose(stdout);
return 0;
}
//coder::by::M91
这里空空如也






有帮助,赞一个