import java.io.PrintStream; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; public class Y433 { Y433() throws Exception { Scanner in = new Scanner(System.in); PrintStream out = new PrintStream(System.out); int n = in.nextInt(); int k = in.nextInt(); School[] school = new School[100001]; for (int i = 0; i < 100001; i++) { school[i] = new School(); } for (int i = 0; i < n; i++) { int s = in.nextInt(); int p = in.nextInt(); int u = in.nextInt(); school[u].add(new Team(s, p, i)); } PriorityQueue pq = new PriorityQueue<>(); for (int i = 0; i < 100001; i++) { if (school[i].teams.size() > 0) { school[i].sort(); pq.add(school[i]); } } for (int i = 0; i < k; i++) { School sch = pq.poll(); Team team = sch.getLast(); out.println(sch.getLast().name); sch.pop(); if (sch.teams.size() > 0) { pq.add(sch); } } } class Team implements Comparable { int s, p, name; Team(int s, int p, int name) { this.s = s; this.p = p; this.name = name; } @Override public int compareTo(Object o) { Team that = (Team) o; if (s != that.s) return Integer.compare(s, that.s); return Integer.compare(that.p, p); } } class School implements Comparable { int passed; List teams; School() { passed = 0; teams = new ArrayList(); } void add(Team t) { teams.add(t); } Team pop() { Team team = getLast(); teams.remove(teams.size() - 1); passed++; return team; } void sort() { teams.sort(null); } Team getLast() { return teams.get(teams.size() - 1); } @Override public int compareTo(Object o) { School that = (School) o; if (getLast().s != that.getLast().s) return Integer.compare(that.getLast().s, getLast().s); if (passed != that.passed) return Integer.compare(passed, that.passed); return Integer.compare(getLast().p, that.getLast().p); } } public static void main(String argv[]) throws Exception { new Y433(); } }