Taking the first k customers that can be satisfied by total amount d
for ( int i = 0 ; i < n ; i ++ ) { if ( v [ i ] . first <= d ) { ans . push_back ( v [ i ] . second ) ; d -= v [ i ] . first ; } } cout << ans . size ( ) << endl ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) cout << ans [ i ] << " ▁ " ; }