#include using namespace std; int n, k; map > > mp; //u,p map > IDS; priority_queue > > q; //selected, penalty university map sel; vector ans; map > > team; //university, pena,id int main(){ cin >> n >> k; for (int i = 0; i < n; i++){ int s, p, u; scanf("%d%d%d", &s, &p, &u); mp[-s].push_back(make_pair(u, p)); IDS[-s].push_back(i); } for (auto it = mp.begin(); it != mp.end(); it++){ vector > &v = (*it).second; for (int i = 0; i < v.size(); i++){ team[v[i].first].push_back(make_pair(v[i].second, IDS[(*it).first][i])); } for (auto it = team.begin(); it != team.end(); it++){ sort((*it).second.begin(), (*it).second.end()); q.push(make_pair(-sel[(*it).first], make_pair(-(*it).second[0].first, (*it).first))); } while (k>0 && q.size()){ pair > b = q.top(); q.pop(); k--; int uni = b.second.second; sel[uni]++; ans.push_back(team[uni].front().second); team[uni].pop_front(); if (team[uni].size()){ q.push(make_pair(-sel[uni], make_pair(-team[uni].front().first, uni)) ); } } team.clear(); } for (int i = 0; i < ans.size(); i++){ printf("%d\n", ans[i]); } return 0; }