Fill Up res [ ] from left to right
for ( int i = 0 ; i < N ; i ++ ) { pq . Sort ( ) ; pq . Reverse ( ) ; int d = pq [ 0 ] ; pq . RemoveAt ( 0 ) ; if ( d != seq [ i ] i == N - 1 ) { res [ i ] = d ; } else {