If it 's size greater than k  it needed to be decreased
while ( int ( val [ cur ] . size ( ) ) > k ) { int elem = val [ cur ] . back ( ) ; val [ cur ] . pop_back ( ) ; extra . push_back ( make_pair ( elem , i ) ) ; }