#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<>n>>k; vector > solves(11, vector()); vector s(n), p(n), u(n); rep(i,n){ scanf("%d %d %d", &s[i], &p[i], &u[i]); u[i]--; solves[s[i]].pb(i); } vector solved(1000000, 0); int cnt=0; for(int sol=10; sol>=0; sol--){ typedef pair P; priority_queue, greater

> pq; for(int i : solves[sol]){ pq.push(mp(solved[u[i]]*1000001L + p[i], i)); } while(!pq.empty() && cnt