fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. signed main(){
  4. int t;
  5. cin>>t;
  6. while(t--){
  7. int n;
  8. cin>>n;
  9. vector<int>arr;
  10. for(int i=0;i<n;i++){
  11. int x;
  12. cin>>x;
  13. arr.push_back(x);
  14. }
  15. int s=0,e=arr.size()-1;
  16. int x=arr[s];
  17. int y=arr[e];
  18. int result=0;
  19. while(s+1<e){
  20. if(x==y){
  21. result=max(result,(s+1)+(n-e));
  22. s++;
  23. x+=arr[s];
  24. }
  25. else if(x<y){
  26. s++;
  27. x+=arr[s];
  28. }
  29. else{
  30. e--;
  31. y+=arr[e];
  32. }
  33. }
  34. if(x==y){
  35. result=max(result,(s+1)+(n-e));
  36. }
  37. cout<<result<<endl;
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5288KB
stdin
4
3
10 20 10
6
2 1 4 2 4 1
5
1 2 4 8 16
9
7 3 20 5 15 1 11 8 10
stdout
2
6
0
7