#K46732. Top K Performers
Top K Performers
Top K Performers
Given one or more datasets, each containing a list of employees with their respective scores, your task is to determine the IDs of the top k performers for each dataset. The employees should be ranked primarily by their scores in descending order, and in case of ties, by their IDs in ascending order. Formally, if two employees i and j have scores \( s_i \) and \( s_j \) respectively, then employee i comes before employee j if either \( s_i > s_j \) or \( s_i = s_j \) and \( id_i < id_j \).
The input consists of multiple datasets. Each dataset begins with two integers n and k representing the number of employees and the number of top performers to select, respectively. It is followed by n lines, each containing an employee's ID and score. The input terminates when a line with "0 0" is encountered.
inputFormat
The input is read from standard input (stdin) and consists of multiple datasets. Each dataset starts with a line containing two integers n and k, where n is the number of employees and k is the number of top performers to select. This is followed by n lines, each with two integers: an employee's ID and the employee's score. The input ends with a line containing "0 0".
outputFormat
For each dataset, output a single line to standard output (stdout) containing the IDs of the top k performers separated by a single space. The ordering should follow the sorting criteria: higher scores come first, and in the event of a tie, the employee with the lower ID appears first. If no dataset is provided, do not output anything.
## sample5 3
101 95
102 90
103 95
104 85
105 90
4 2
201 100
202 100
203 50
204 50
0 0
101 103 102
201 202
</p>