#include using namespace std; typedef long long ll; typedef vector< int > vi; typedef vector< vi > vvi; typedef vector< ll > vl; typedef vector< vl > vvl; typedef pair< int, int > pii; typedef vector< pii > vp; typedef vector< double > vd; typedef vector< vd > vvd; typedef vector< string > vs; template< class T1, class T2 > int upmin( T1 &x, T2 v ){ if( x > v ){ x = v; return 1; } return 0; } template< class T1, class T2 > int upmax( T1 &x, T2 v ){ if( x < v ){ x = v; return 1; } return 0; } const int INF = 0x3f3f3f3f; int N, K; vi S, P, U; void init(){ cin >> N >> K; S = P = U = vi( N ); for( int i = 0; i < N; ++i ) cin >> S[ i ] >> P[ i ] >> U[ i ]; } vi ans; void preprocess(){ vvi s2id( 10 + 1 ); for( int i = 0; i < N; ++i ) s2id[ S[ i ] ].emplace_back( i ); for( int i = 10; i >= 0; --i ){ vi ucnt( ( int ) 1e5 + 1 ); for( int j = 0; j < ans.size(); ++j ) ++ucnt[ U[ ans[ j ] ] ]; vector< priority_queue< tuple< int, int > > > pq( ( int ) 1e5 + 1 ); for( int j = 0; j < N; ++j ) if( S[ j ] == i ) pq[ U[ j ] ].emplace( -P[ j ], j ); priority_queue< tuple< int, int, int > > upq; for( int j = 0; j <= ( int ) 1e5; ++j ) if( not pq[ j ].empty() ) upq.emplace( -ucnt[ j ], get< 0 >( pq[ j ].top() ), j ); while( not upq.empty() and ans.size() < K ){ int uc, p, u; tie( uc, p, u ) = upq.top(); upq.pop(); int x, id; tie( x, id ) = pq[ u ].top(); pq[ u ].pop(); ans.emplace_back( id ); if( not pq[ u ].empty() ) upq.emplace( uc - 1, get< 0 >( pq[ u ].top() ), u ); } } } void solve(){ for( int i = 0; i < K; ++i ) cout << ans[ i ] << endl; } signed main(){ ios::sync_with_stdio( 0 ); init(); preprocess(); solve(); return 0; }