#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) #define fst first #define snd second using ll=long long;using pii=pair;using vb=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; template T read() {T t; cin >> t; return t;} using iii = pair; void Main() { int N = read(); int K = read(); map> smap; map uc; rep(i, N) { int s = read(); int p = read(); int u = read(); smap[-s][u].emplace_back(p, i); } vi ans; forr(st, smap) { map &uteams = st.snd; vi us; forr(uts, uteams) { us.push_back(uts.fst); sort(ALL(uts.snd), greater()); } sort(ALL(us)); us.erase(unique(us.begin(), us.end()), us.end()); priority_queue, greater > q; forr(u, us) q.push({uc[u], {uteams[u][SZ(uteams[u])-1].fst, u}}); while (!q.empty() && K) { int u = q.top().snd.snd; q.pop(); vpii &teams = uteams[u]; int idx = teams[SZ(teams)-1].snd; ans.push_back(idx); teams.pop_back(); uc[u]++; K--; if (SZ(teams)) { q.push({uc[u], {uteams[u][SZ(uteams[u])-1].fst, u}}); } } } forr(i, ans) cout << i << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }