Check if any P continuous columns were left unpainted
for ( int i = 0 ; i < N ; i ++ ) { if ( vis [ i ] == false ) continuousCol ++ ; else { maxContinuousCol = max ( maxContinuousCol , continuousCol ) ; continuousCol = 0 ; } } maxContinuousCol = max ( maxContinuousCol , continuousCol ) ;