#K79107. Marathon Ranking Management
Marathon Ranking Management
Marathon Ranking Management
You are given the initial registration of participants in a marathon. Each participant is identified by a unique string and an initial race time. Afterwards, you will receive a series of operations. There are two kinds of operations:
UPDATE <identifier> <new_time>
: Update the participant's best race time if the new time is lower than their current best.RANKING
: Output the current ranking of participants ordered by their best times (in ascending order). If two participants have the same time, sort them lexicographically by their identifier.
Your task is to process these operations and, whenever a RANKING
operation appears, print the ranking in a specific format. The ranking should list each participant as identifier:time
separated by commas on one line.
In mathematical terms, for every ranking query, you should output a list sorted according to the key \( (time, identifier) \) .
inputFormat
The input is read from standard input and is formatted as follows:
- An integer n representing the number of participants.
- n lines follow, each containing a participant's identifier and their initial time separated by a space.
- An integer q representing the number of operations.
- q lines follow, each being either an update operation of the form
UPDATE identifier new_time
or the commandRANKING
.
outputFormat
For each RANKING
operation, output a single line that represents the ranking of participants. Each participant is printed in the format identifier:time
, and the participants are separated by commas. The output should be written to standard output.
3
alice 360.5
bob 359.3
charlie 360.5
1
RANKING
bob:359.3,alice:360.5,charlie:360.5
</p>