Charting Only the Top 5
Alderwood Supply's category report covers dozens of lines, and a bar chart with dozens of bars is a wall of grey nobody reads. The report therefore shows only the five biggest, tallest first, and puts everything else in a table further down. Under the chart the same five names are listed in the same order, and that list is what is checked here. Where fewer than five lines exist, all of them are listed. Two lines with exactly equal values keep the order they had in the file.
Task: Print the names of the five highest-valued items, largest first.
Input
The first line holds an integer n, the number of items. Each of the next n lines holds an item name and its value, separated by a single space. A name contains no spaces.
Output
Up to five lines, one item name per line, in decreasing order of value. If the file holds fewer than five items, list every one of them.
Example:
Input:
6
A 10
B 90
C 50
D 20
E 70
F 5
Output:
B
E
C
D
A
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in