#include using namespace std; // macros #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define MIN(a,b) (a>b?b:a) #define MAX(a,b) (a>b?a:b) #define INT_IN(a) int a; cin >> a #define STR_IN(s) string s; cin >> s #define PRINTLN(s) cout << s << endl #define PRINTDOUBLELN(s) cout << setprecision(12) << (s) << endl; // util functions template inline T sqr(T x) {return x*x;} inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template inline string toString(T x) {ostringstream sout;sout<inline T max(vector v){T max=v[0]; FOR(i, 1, v.size())max=MAX(v[i], max); return max;} template inline T min(vector v){T min=v[0]; FOR(i, 1, v.size())min=MIN(v[i], min); return min;} template inline vector concat(vector a, vector b){vector ab; ab.reserve(a.size()+b.size());ab.insert(ab.end(),a.begin(),a.end());ab.insert(ab.end(),b.begin(),b.end());return ab;} // types typedef long long LL; // consts const double EPS = 1e-10; const double PI = acos(-1.0); //debug #define dump(x) #x << " = " << (x) << endl #define debug(x) #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl struct team{ team(int S, int P, int U) : score(S), penalty(P), univId(U){}; int score; int penalty; int univId; }; vector selUniv(100000); int main(){ INT_IN(N); INT_IN(K); vector teams; REP(i, N){ INT_IN(S); INT_IN(P); INT_IN(U); teams.push_back(team(S, P, U)); } sort(teams.begin(), teams.end(), [](const team& a, const team& b){ return a.score != b.score ? a.score > b.score : a.penalty != b.penalty ? a.penalty < b.penalty : a.univId < b.univId; }); while(K){ int mS = teams[0].score; int nmS = 0; // candidate teams vector selT; for(int i = 0; teams[i].score == nmS; i++){ selT.push_back(i); } while(K && selT.size()){ int lowP = teams[selT[0]].penalty; // second candidate teams vector sel2T; for(int i = 0; teams[selT[i]].penalty == lowP; i++){ sel2T.push_back(selT[i]); } sort(sel2T.begin(), sel2T.end(), [teams](const int a, const int b){ return selUniv[teams[a].univId] < selUniv[teams[b].univId]; }); while(K && sel2T.size()){ PRINTLN(sel2T[0]); sel2T.erase(sel2T.begin()); selT.erase(selT.begin()); K--; } } } return 0; }