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