#K3251. Participant Ranking

    ID: 24917 Type: Default 1000ms 256MiB

Participant Ranking

Participant Ranking

You are given a list of participants along with their scores from one or more checkpoints. Your task is to rank these participants based on their total score. The participant with the highest total score should come first. In the case of a tie (i.e. two participants having the same total score), the participant whose name is lexicographically smaller should be ranked higher.

Mathematically, if the total score of participant i is given by \(S_i = s_{i,1} + s_{i,2} + \dots + s_{i,k}\), then the ordering is determined by:

[ \text{Sort by } S \text{ in descending order, and if } S_i = S_j, \text{ then sort by name in ascending order.} ]

You should read input from the standard input (stdin) and output the results to the standard output (stdout).

inputFormat

The first line contains an integer \(n\) representing the number of participants.

The next \(n\) lines each contain the description of a participant: a name (a string without spaces) followed by one or more integers representing the scores at different checkpoints, all separated by spaces.

Example:

5
alice 4 5 1 3 10
bob 6 1 8 3 5 3
charlie 5 5 10
david 7 7 7 5 6 4
eve 2 2 2 2 2

outputFormat

Output the names of the participants after ranking them according to the rules described. Each participant's name should be printed on a new line in the correct order.

For the sample input above, the output should be:

david
bob
alice
charlie
eve
## sample
5
alice 4 5 1 3 10
bob 6 1 8 3 5 3
charlie 5 5 10
david 7 7 7 5 6 4
eve 2 2 2 2 2
david

bob alice charlie eve

</p>