A choir director arranges every singer on a set of risers so that the tallest singers stand at the back and the shortest stand at the front. You are given each singer's name together with their height. Rearrange the singers from tallest to shortest and report their names in that order.
The first line contains a single integer n, the number of singers. Each of the next n lines contains one singer's name and height, separated by a single space, in the form name height.
Print n lines: the singers' names ordered from tallest to shortest.
Example 1
Input
3 alice 150 bob 170 carol 160
Expected
bob carol alice
Explanation
Bob is tallest at 170, carol is next at 160, and alice is shortest at 150, so the output lists bob, then carol, then alice.
Example 2
Input
4 Emma 130 Liam 145 Olivia 138 Noah 150
Expected
Noah Liam Olivia Emma
Explanation
Sorting the four heights in descending order gives Noah (150), Liam (145), Olivia (138), Emma (130), which is the order their names are printed in.
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 →