#C4790. Find Top K Participants

    ID: 48367 Type: Default 1000ms 256MiB

Find Top K Participants

Find Top K Participants

You are given an integer \( n \) representing the number of score entries and an integer \( k \). Each of the next \( n \) lines contains a participant ID (a string) and a score (an integer). Your task is to compute the total score for each participant and then return the top \( k \) participants sorted in descending order of their total scores. If two participants have the same total score, they should be ordered by their participant IDs in lexicographical (ascending) order.

Note: All formulas are provided in LaTeX format. The input is given via standard input (stdin) and the result should be output to standard output (stdout).

inputFormat

The first line contains two space-separated integers, \( n \) and \( k \). Each of the following \( n \) lines contains a string (participant ID) and an integer (score), separated by a space.

outputFormat

Output a single line containing the top \( k \) participant IDs separated by a single space, ordered by the rules described above.

## sample
6 3
alice 50
bob 80
alice 20
charlie 30
bob 40
charlie 70
bob charlie alice