#K73627. Top K Unique Scores for Each Player
Top K Unique Scores for Each Player
Top K Unique Scores for Each Player
You are given n records of players' scores. Each record contains two integers: a player id and a score. Some records may contain duplicate scores for a given player. Your task is to compute the top k distinct scores for each player and output the result sorted by player id in ascending order.
For each player, you must select the highest unique scores in descending order. If a player has fewer than k unique scores, output all of their unique scores sorted from highest to lowest.
The mathematical representation is as follows: Given a set \(S_p\) for each player p with scores, you need to compute the sorted list of scores: \[ \text{TopK}(S_p) = \text{first } k \text{ elements of } (\{s: s \in S_p\} \text{ sorted in descending order}) \]
inputFormat
The first line of the input contains two space-separated integers: n (the number of records) and k (the number of top unique scores to output for each player).
Each of the following n lines contains two space-separated integers: the player id and the score.
Example:
6 2 1 100 2 150 1 200 2 150 1 100 2 180
outputFormat
For each player, output one line containing the player's id followed by their top k unique scores in descending order. The players should be output in ascending order of their ids.
Example:
1 200 100 2 180 150## sample
6 2
1 100
2 150
1 200
2 150
1 100
2 180
1 200 100
2 180 150
</p>