If it 's size is less than k  it needed to be increased
while ( val [ cur ] . size ( ) < k && ! extra . isEmpty ( ) ) { int elem = extra . get ( extra . size ( ) - 1 ) . first ; int mmod = extra . get ( extra . size ( ) - 1 ) . second ; extra . remove ( extra . size ( ) - 1 ) ; val [ cur ] . add ( elem ) ; ans += i - mmod ; } } return ( int ) ans ; }