#include using namespace std; #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,1,0,-1,1,-1,1,-1}; template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } struct node{ ll p,u,id; bool operator<(node &b){ return p> n >> k; map> mp; rep(i,n){ ll s,p,u;cin >> s >> p >> u; mp[-s].push_back({p,u,i}); } vl use; vl solve(1e6); for(auto [hoge,v]:mp){ map> univ;//大学ごと for(auto p:v){ univ[p.u].emplace_back(p); } for(auto &p:univ)sort(all(p.second)),rev(all(p.second)); set> st; for(auto p:univ){ st.insert(make_tuple(solve[p.second.back().u],p.second.back().p,p.first)); } while(k){ if(st.size()==0)break; auto f=*st.begin();st.erase(st.begin()); auto un=get<2>(f); solve[un]++;use.emplace_back(univ[un].back().id); univ[un].pop_back(); if(univ[un].size()){ st.insert(make_tuple(solve[univ[un].back().u],univ[un].back().p,un)); } k--; } } for(auto p:use)cout << p << endl; }