fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. long long T,n,s1,s2;
  5. int a[1001];
  6. long long s[1001];
  7. int main() {
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(NULL);
  10. cin >> T;
  11. while(T--)
  12. {
  13. cin >> n;
  14. s[0] = 0;
  15. bool ok = false;
  16. for(int i = 1; i <= n; i++) cin >> a[i];
  17. s[1] = a[1];
  18. for(int i = 2; i <= n; i++) s[i] = s[i-1] + a[i];
  19. for(int i = 1; i <= n; i++)
  20. {
  21. s1 = s[i-1];
  22. s2 = s[n] - s[i];
  23. if(s1 == s2) {
  24. cout << i << endl;
  25. ok=true;
  26. break;
  27. }
  28. }
  29. if(ok == false) cout << -1 << endl;
  30. }
  31. return 0;
  32. }
  33. //ewwww... brother ewwwwwwwwww... whats that? whats that
Success #stdin #stdout 0s 5284KB
stdin
3
2
1 2
3
2 1 2
5
1 2 3 4 6
stdout
-1
2
4