Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int t;
- cin >> t;
- while (t--) {
- int n;
- cin >> n;
- vector<int> a(n);
- for (auto &i: a)
- cin >> i;
- long long cur = 0;
- int start = 0;
- while(start < n){
- while(start < n && a[start] == 1)
- start++;
- if(start == n)
- break;
- if(a[start] + start >= n){
- cur += a[start] - max((n - start - 1), 1);
- a[start] = max(n - start - 1, 1);
- }
- while(a[start] > 1){
- int w = start;
- while(w < n) {
- int prev = a[w];
- a[w] = max(a[w] - 1, 1), w += prev;
- }
- cur++;
- }
- }
- cout << cur << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment