#K91247. Leaderboard Operations
Leaderboard Operations
Leaderboard Operations
You are given a series of operations to manage a leaderboard. The operations may either add/update a player's score or query the leaderboard for the top K players.
Operations
add playerName score
: If the player does not exist, add them with the given score. If the player exists and the new score is higher than their current best score, update their score. If the new score is not higher, ignore the operation.top K
: Query the leaderboard to get the names of the top K players.
The ranking is determined by the player's best score in descending order. If multiple players have the same score, the player who achieved that score earlier (i.e. the smallest update order) will be ranked higher.
Input Format: The first line contains an integer n, representing the number of operations. Each of the next n lines contains an operation, either an add operation or a top query.
Output Format: For each top
query, output a line containing the list of top K players separated by a single space.
The scoring formula in this problem can be stated as follows in LaTeX:
$$\text{rank}(i) = \text{sorted}(\{(score, order)\})\text{ in descending order of }score\text{ and ascending order of }order. $$inputFormat
The input consists of multiple lines. The first line contains a single integer n which represents the number of operations. The following n lines each contain a command:
add playerName score
top K
It is guaranteed that at least one top
command is present in the input.
outputFormat
For each top
operation in the input, output a line that contains the names of the top K players separated by a single space.
5
add alice 50
add bob 60
top 1
add alice 70
top 2
bob
alice bob
</p>