#C9193. Dynamic Game Leaderboard
Dynamic Game Leaderboard
Dynamic Game Leaderboard
The dynamic game leaderboard problem requires you to handle two types of operations sequentially. The operations include updating a player's score and calculating the sum of the top \(k\) scores. When an Add i s
operation is provided, you should update the score of player \(i\) to \(s\) (adding the player if they do not already exist). When a Top k
operation is provided, you must calculate the sum of the top \(k\) scores from all players.
Formally, if the scores are \(s_1, s_2, \dots, s_n\), then for a query Top k
, your task is to find \(\sum_{j=1}^{k} s_{(j)}\) where \(s_{(1)} \geq s_{(2)} \geq \cdots \geq s_{(n)}\) is the sequence of scores sorted in non-increasing order. Use an efficient data structure to handle multiple updates dynamically.
inputFormat
The first line of the input contains an integer \(N\) representing the number of operations. Each of the next \(N\) lines contains one operation, which can be one of the following:
Add i s
: Update the score of the player with id \(i\) to \(s\). If the player does not exist, add them.Top k
: Output the sum of the top \(k\) scores among all players.
The input is to be read from standard input.
outputFormat
For each Top
operation, print a single line containing the sum of the top \(k\) scores. The outputs should be produced in the order that the Top
operations appear in the input, printed to standard output.
7
Add 1 20
Add 2 30
Top 1
Add 1 50
Top 2
Add 3 60
Top 2
30
80
110
</p>