#include #define endl '\n' #define ll long long using namespace std; const int N = 1e5 + 10; int n, k; struct node{ int id, s, p, u; }a[N]; vector < pair < pair , int > > U[N]; priority_queue < pair < pair , pair > > pq; int cnt[N]; int main() { //freopen("icpc.in","r",stdin); //freopen("icpc.out","w",stdout); cin >> n >> k; for (int i = 0; i < n; i ++) { a[i].id = i; cin >> a[i].s >> a[i].p >> a[i].u; U[a[i].u].push_back({{a[i].s, -a[i].p}, i}); } for (int i = 1; i < N; i ++) { if (!U[i].empty()) { sort(U[i].begin(), U[i].end()); int x = U[i].back().second; U[i].pop_back(); pq.push({{a[x].s, 0}, {-a[x].p, x}}); } } while (k --) { pair < pair , pair > t = pq.top(); pq.pop(); int x = t.second.second; cout << x << '\n'; if (!U[a[x].u].empty()) { cnt[a[x].u] ++; int y = U[a[x].u].back().second; U[a[x].u].pop_back(); pq.push({{a[y].s, -cnt[a[y].u]}, {-a[y].p, y}}); } } return 0; } //Fuck you, Japan.