Aggregating Before Charting
Fernbrook Analytics has a client with thousands of readings per region, and a panel with one dot per reading is unreadable. The agreed compromise is one dot per region, positioned at that region's average reading. Someone always asks which region came out on top, so the tool prints that name rather than leaving it to be read off the panel.
Task: Print the region with the highest average reading.
Input
The first line holds one integer n, the number of readings. Each of the next n lines holds a region name and one reading, separated by a single space. Region names contain no spaces, and a region may appear on many lines.
Output
One line holding a single region name, exactly as it was read. A region's average is the average of its own readings, so a region with two readings competes on equal terms with one that has two hundred. If two regions tie on average, print whichever comes first alphabetically.
Example:
Input:
4
East 10
East 20
West 100
West 50
Output:
West
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