#K35527. Top K Participants

    ID: 25551 Type: Default 1000ms 256MiB

Top K Participants

Top K Participants

You are given n participants, each with a name and a score. Your task is to select the top k participants based on their scores.

The participants should be ordered primarily by their score in descending order. In case of a tie, the names should be sorted in lexicographical (alphabetical) order. Formally, if two participants i and j have the same score, then i comes before j if name[i] < name[j] (using standard string comparison).

Mathematically, if we denote a participant by a tuple \( (name, score) \), you need to sort them so that for any two participants \( a = (name_a, score_a) \) and \( b = (name_b, score_b) \):

\[ (a, b) : \; score_a > score_b \quad \text{or} \quad (score_a = score_b \; \text{and} \; name_a < name_b) \]

Finally, output the names of the top k participants in order, each on a new line.

inputFormat

The input is read from standard input (stdin) and has the following format:

n k
name1 score1
name2 score2
... 
namen scoren

Here, n is the total number of participants and k is the number of top participants to output. Each of the following n lines contains a participant's name and score separated by a space. The score can be a negative or positive integer.

outputFormat

Output to standard output (stdout) exactly k lines, each containing the name of a participant, in the order determined by the sorting rules.

## sample
7 3
Alice 86
Bob 92
Charlie 92
David 85
Eve 91
Frank 89
Grace 85
Bob

Charlie Eve

</p>