#K53107. Scoreboard Operations

    ID: 29458 Type: Default 1000ms 256MiB

Scoreboard Operations

Scoreboard Operations

You are given a series of operations to manage a scoreboard. The scoreboard keeps track of participants' scores. There are two types of operations:

  • add <name> <score>: Add a new participant with the given score or update the score of an existing participant.
  • top <k>: Output the names of the top k participants, ordered first by their score (in descending order) and then by their name in lexicographical order (if ties occur).

Mathematically, if participants have scores \( s_i \) and names \( n_i \), then when sorting, a participant \( i \) precedes participant \( j \) if either \[ s_i > s_j \] or \[ s_i = s_j \quad \text{and} \quad n_i < n_j, \] where \( n_i < n_j \) is determined by lexicographic order.

You need to process all operations and for each top command, output a single line comprising the space-separated names of the top k participants.

inputFormat

The input is given via standard input (stdin) with the following format:

  1. An integer \( n \) representing the number of operations.
  2. \( n \) lines follow, each representing an operation in one of the following formats: add <name> <score> or top <k>.

Names are strings without spaces, and scores and k are integers.

outputFormat

For each top operation, output a line containing the space-separated names of the top \( k \) participants based on the current state of the scoreboard.

## sample
7
add Alice 50
add Bob 75
add Alice 100
top 1
add Carol 100
add Bob 50
top 3
Alice

Alice Carol Bob

</p>