#C605. Leaderboard

    ID: 49767 Type: Default 1000ms 256MiB

Leaderboard

Leaderboard

You are required to implement a Leaderboard data structure that supports the following three operations:

  • addScore player score: If the player already exists, add the given score to the player's current score; otherwise, add the player with the specified score.
  • top K: Print the sum of the top \(K\) highest scores in the leaderboard. If there are fewer than \(K\) players, sum all the players' scores.
  • reset player: Reset the score of the given player to zero.

You will be given a sequence of operations from the standard input. Process each operation and, for every top operation, output the result to the standard output (each on a new line).

Note: All input and output operations must be performed via stdin and stdout.

inputFormat

The first line of the input contains an integer \(N\) representing the number of operations.

The next \(N\) lines each represent an operation, which can be one of the following three formats:

  • addScore player score — where player is a string and score is an integer.
  • top K — where K is an integer.
  • reset player — where player is a string.

outputFormat

For each top operation, output a single line containing one integer: the sum of the top \(K\) scores after processing the operations so far.

## sample
7
addScore Alice 50
top 1
addScore Bob 30
top 2
addScore Alice 20
top 1
reset Alice
50

80 70

</p>