12501 - Ape Society   

Description

Morris is a smart ape. His work is to teach N small apes the rules in the ape society.
Morris wanted to know how much small apes learned, therefore, he held a midterm exam last week. The result of exam made Morris so mad that he decided to flunk M-last apes.

Morris has the names, grades, and ages of these apes.
Can you help Morris to find the M-last apes by following rules?

Between two apes, the ape with the greater grade is better than the other one.
If they have the same grades, the younger ape is better than the older ape.
If they have the same grades and ages, compare their names in lexicographical order. The ape with small name is better than the other one.

Input

Two integer NM on the first line.
The following N lines contain information of apes.
Each line is consisted of SGA representing the name, grade, age of an ape respectively.

  • ≤ ≤ 1,000
  • ≤ ≤ N
  • ≤ G, ≤ 100
  • ≤ |S≤ 10
  • it’s guaranteed that the names are different.

Output

Print M lines of apes’ name which will be flunked by Morris.
The output order is ascending order, which means the worst ape will be printed first, and then the second last, the third last, and so on.

Sample Input  Download

Sample Output  Download

Tags




Discuss