fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define nl '\n'
  5.  
  6. void fastio() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. cout.tie(nullptr);
  10. }
  11.  
  12. void solve() {
  13. int n; cin >> n;
  14. vector<int> v(n);
  15. for(int i = 0; i < n; i++) cin >> v[i];
  16.  
  17.  
  18. for (int i = 0; i < n - 1; i++) {
  19. if (v[i] <= 0 && v[i + 1] <= 0) {
  20. v[i] = abs(v[i]);
  21. v[i + 1] = abs(v[i + 1]);
  22. }
  23. }
  24.  
  25. ll sum = accumulate(v.begin(), v.end(), 0LL);
  26. cout << sum << nl;
  27. }
  28.  
  29. int main() {
  30. fastio();
  31. int t = 1;
  32. cin >> t;
  33. while (t--) {
  34. solve();
  35. }
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 5316KB
stdin
5
3
-1 -1 -1
5
1 5 -5 0 2
3
1 2 3
6
-1 10 9 8 7 6
2
-1 -1
stdout
1
13
6
39
2