#C394. Marathon Race Results

    ID: 47422 Type: Default 1000ms 256MiB

Marathon Race Results

Marathon Race Results

In this problem, you are given the checkpoint times of several runners during a marathon. Each runner passes through 4 checkpoints, and the times are provided in the 24-hour format (HH:MM:SS). Your task is to determine the final standings based on the finishing times (i.e. the time at the final checkpoint). If two or more runners finish at the same time, they are considered tied; in such a case, sort the tied runners alphabetically and append the label " (tie)" to the names.

For example, if runner Bob and runner Diana both finish at the same time and have the best finish time, they share the 1st position (displayed as "1st: Bob, Diana (tie)"). The next available rank after a tie should be incremented by the number of tied runners.

inputFormat

Input is read from standard input (stdin). The first line contains an integer (T) representing the number of runners. Each of the following (T) lines contains a runner’s name followed by 4 checkpoint times in the format (HH:MM:SS), separated by spaces. For example:

4
Alice 00:15:30 00:30:25 00:45:10 01:10:05
Bob 00:14:25 00:28:20 00:42:30 01:05:25
Charlie 00:17:10 00:34:05 00:50:00 01:12:10
Diana 00:16:25 00:32:20 00:48:05 01:08:25

outputFormat

Output the final standings to standard output (stdout). Each line should contain the rank (with the appropriate ordinal suffix) followed by a colon, a space, and the runner’s name. In the case of ties, list all tied names in alphabetical order, separated by commas, and append " (tie)" at the end. For example:

1st: Bob
2nd: Diana
3rd: Alice
4th: Charlie## sample

4
Alice 00:15:30 00:30:25 00:45:10 01:10:05
Bob 00:14:25 00:28:20 00:42:30 01:05:25
Charlie 00:17:10 00:34:05 00:50:00 01:12:10
Diana 00:16:25 00:32:20 00:48:05 01:08:25
1st: Bob

2nd: Diana 3rd: Alice 4th: Charlie

</p>