A tournament tracks each player's score and number of wins. Produce the final standings by sorting the players with this exact comparator:
score ranks first.wins ranks first.name is lexicographically smaller ranks first.Player names are lowercase letters only and are guaranteed to be distinct, so the ordering is uniquely determined.
Line 1: an integer n — the number of players.
Next n lines: each contains name score wins separated by single spaces.
Print n lines. Line i contains name score for the player ranked i-th (1-indexed) in the standings. (Wins are used only for ordering and are not printed.)
Example 1
Input
3 alice 50 3 bob 50 5 cara 40 9
Expected
bob 50 alice 50 cara 40
Explanation
alice and bob tie on score 50, so wins break the tie: bob (5 wins) outranks alice (3 wins). cara has the lowest score and comes last.
Example 2
Input
2 zoe 10 2 abe 10 2
Expected
abe 10 zoe 10
Explanation
Both players tie on score (10) and wins (2), so the name decides: 'abe' < 'zoe', so abe ranks first.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →