import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Main { public static class Team implements Comparable{ int index, score, penalty, univ, univ_count; public Team(int index, int score, int penalty, int univ, int univ_count){ this.index = index; this.score = score; this.penalty = penalty; this.univ = univ; this.univ_count = univ_count; } public int compareTo(Team arg0){ if(this.score != arg0.score){ return -Integer.compare(this.score, arg0.score); }else if(this.univ_count != arg0.univ_count){ return Integer.compare(this.univ_count, arg0.univ_count); }else{ return Integer.compare(this.penalty, arg0.penalty); } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int K = sc.nextInt(); Team[] teams = new Team[N]; for(int i = 0; i < N; i++){ final int S = sc.nextInt(); final int P = sc.nextInt(); final int U = sc.nextInt(); teams[i] = new Team(i, S, P, U, 0); } HashMap> univ_hash = new HashMap>(); HashMap univ_count = new HashMap(); for(final Team t : teams){ if(!univ_hash.containsKey(t.univ)){ univ_hash.put(t.univ, new PriorityQueue()); } if(!univ_count.containsKey(t.univ)){ univ_count.put(t.univ, 0); } univ_hash.get(t.univ).add(t); } LinkedList answer = new LinkedList(); PriorityQueue queue = new PriorityQueue(); for(final PriorityQueue q : univ_hash.values()){ queue.add(q.poll()); } for(int i = 0; i < K; i++){ final Team ok = queue.poll(); answer.add(ok); final Team next_add = univ_hash.get(ok.univ).poll(); if(next_add != null){ next_add.univ_count = ok.univ_count + 1; queue.add(next_add); } } for(final Team t : answer){ System.out.println(t.index); } } }