#C714. Leaderboard Tracker
Leaderboard Tracker
Leaderboard Tracker
You are given the task of implementing a leaderboard for a game. The leaderboard should be able to keep track of players' scores and perform three types of operations:
- Add Score: Increment the score of a given player by a specified amount. If the player does not exist, add them to the leaderboard.
- Top: Return the sum of the scores of the top \(K\) players. That is, if you sort all players by their scores in decreasing order, return the sum of the first \(K\) scores.
- Reset: Reset a given player's score to 0.
You will receive a series of operations. Your task is to process these operations and, for every Top
command, output the corresponding sum.
Note: All formulas appear in \(\LaTeX\) format when necessary.
inputFormat
The first line of the input contains an integer \(n\) representing the number of operations. The following \(n\) lines each describe an operation in one of the following formats:
1 playerId score
: Addscore
to the player's current score (i.e., perform theaddScore
operation).2 K
: Output the sum of the top \(K\) scores (i.e., perform thetop
operation).3 playerId
: Reset the player's score to 0 (i.e., perform thereset
operation).
All operations are given via stdin.
outputFormat
For each operation of type 2
(top), print the resulting sum on a new line to stdout.
5
1 1 100
1 2 200
2 1
3 1
2 1
200
200
</p>