If it 's size greater than k  it needed to be decreased
while ( ( val [ cur ] . size ( ) ) > k ) { int elem = val [ cur ] . lastElement ( ) ; val [ cur ] . removeElementAt ( val [ cur ] . size ( ) - 1 ) ; extra . add ( new pair ( elem , i ) ) ; }