#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define RREP(i, a) for (int (i) = (a) - 1; (i) >= 0; (i)--) #define FORR(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--) #define PI acos(-1.0) #define DEBUG(C) cerr << C << endl; #define VI vector #define VII vector #define VL vector #define VLL vector #define VD vector #define VDD vector #define PII pair #define PDD pair #define PLL pair #define VPII vector #define ALL(a) (a).begin(), (a).end() #define SORT(a) sort(ALL(a)) #define REVERSE(a) reverse(ALL(a)) #define MP make_pair #define EB emplace_back #define FORE(a, b) for (auto &&a : b) #define FIND(s, n) (s.find(n) != s.end()) using namespace std; typedef long long LL; typedef unsigned long long ULL; const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; int N, K; vector> SPU; //解いた問題で云々 //map>> ac; //(正答数, SPU) //map>> school; //(学校, SPU) //map>> pena; //(ペナ数, SPU) vector>> ac, school, pena; vector sccnt; set used; int main(void) { cin >> N >> K; SPU.resize(N); ac.resize(12); school.resize((int)1e5 + 10); pena.resize((int)1e6 + 10); sccnt.resize(N, 0); REP(i, N) { int s, p, u; //cin >> s >> p >> u; scanf("%d%d%d", &s, &p, &u); auto tt = make_tuple(s, p, u, i); SPU[i] = tt; ac[s].emplace(tt); school[u].emplace(tt); pena[p].emplace(tt); } while(ac.back().size() == 0) ac.pop_back(); SORT(SPU);REVERSE(SPU); REP(_, K) { auto itr = ac.end(); itr--; if ((*itr).size() == 0) { ac.erase(itr); itr = ac.end(); itr--; } if ((*itr).size() == 1) { int s,p,u,n; FORE(el, (*itr)) { //cout << get<3>(el) << endl; printf("%d\n", get<3>(el)); //DEBUG("AC数") tie(s, p, u, n) = el; } sccnt[u]++; ac[s].erase(make_tuple(s, p, u, n)); school[u].erase(make_tuple(s, p, u, n)); pena[p].erase(make_tuple(s, p, u, n)); } else { //学校からの突破数で比較 int s, p, u, n; int mokuhyonum = INF; set> se; FORE(el, (*itr)) { tie(s, p, u, n) = el; if (mokuhyonum > sccnt[u]) { se.clear(); se.insert(el); mokuhyonum = sccnt[u]; } else if (mokuhyonum == sccnt[u]) { se.insert(el); } } if (se.size() == 1) { FORE(el, se) { //cout << get<3>(el) << endl; printf("%d\n", get<3>(el)); //DEBUG("school数") tie(s, p, u, n) = el; sccnt[u]++; ac[s].erase(make_tuple(s, p, u, n)); school[u].erase(make_tuple(s, p, u, n)); pena[p].erase(make_tuple(s, p, u, n)); } } else { //ペナ数で比較 int s, p, u, n; int minpena = INF; tuple ans; FORE(el, se) { tie(s, p, u, n) = el; if (minpena > p) { minpena = p; ans = el; } } //cout << get<3>(ans) << endl; printf("%d\n", get<3>(ans)); //DEBUG("pena数") tie(s, p, u, n) = ans; sccnt[u]++; ac[s].erase(make_tuple(s, p, u, n)); school[u].erase(make_tuple(s, p, u, n)); pena[p].erase(make_tuple(s, p, u, n)); } } } }