Recover the Arrays

  • + 0 comments
    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main(){
        int n,a[100000];
        cin>>n;
        for(int i=0;i<n;i++)
            cin>>a[i];
        int x=a[0], count=0, y=0;
        while(y<n)
            {
            y+=(x+1);
            x=a[y];
            count++;
        }
        cout<<count;
        return 0;
    }