fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7. while(t--){
  8. int n, sum = 0;
  9. cin >> n;
  10. int a[n];
  11. for(int i=0;i<n;i++){
  12. cin >> a[i];
  13. sum = sum + a[i];
  14. }
  15. for(int i=0;i<n;i++){
  16. if(a[i] == -1 && a[i+1] == -1){
  17. break;
  18. }
  19. cout << sum + 4 << "\n";
  20. }
  21.  
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5312KB
stdin
4
5
-1 1 1 -1 -1
5
1 1 -1 -1 -1
2
1 1
4
1 -1 -1 1
stdout
3
3
3
3
3
6
6
4