0w1

CFR 583 B. Robot's Task ( Ad hoc )

Problem - B - Codeforces
We will simply go as far as we can each time, so we will sweep from left to right, that from right to left, ... until there are no more left.

void solve(){
    int N; cin >> N;
    vi A( N );
    for( int i = 0; i < N; ++i )
        cin >> A[ i ];
    vi vis( N );
    int ans = 0;
    for( int i = 0, pcnt = 0, cnt = N; i < N; ++i ){
        if( cnt == 0 ) break;
        ans = i;
        if( i % 2 == 0 ){
            for( int j = 0; j < N; ++j )
                if( not vis[ j ] and pcnt >= A[ j ] )
                    vis[ j ] = 1,
                    ++pcnt,
                    --cnt;
        } else{
            for( int j = N - 1; j >= 0; --j )
                if( not vis[ j ] and pcnt >= A[ j ] )
                    vis[ j ] = 1,
                    ++pcnt,
                    --cnt;
        }
    }
    cout << ans << endl;
}