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