ProgMe

Untitled

Feb 28th, 2021
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int32_t main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8. cout.tie(nullptr);
  9. int t;
  10. cin >> t;
  11. while (t--) {
  12. int n;
  13. cin >> n;
  14. vector<int> a(n);
  15. for (auto &i: a)
  16. cin >> i;
  17. long long cur = 0;
  18. int start = 0;
  19. while(start < n){
  20. while(start < n && a[start] == 1)
  21. start++;
  22. if(start == n)
  23. break;
  24. if(a[start] + start >= n){
  25. cur += a[start] - max((n - start - 1), 1);
  26. a[start] = max(n - start - 1, 1);
  27. }
  28. while(a[start] > 1){
  29. int w = start;
  30. while(w < n) {
  31. int prev = a[w];
  32. a[w] = max(a[w] - 1, 1), w += prev;
  33. }
  34. cur++;
  35. }
  36. }
  37. cout << cur << '\n';
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment