A small coastal harbor keeps a single ledger of every fish dock that sold its catch today. Each entry lists a dock's name and the price its catch fetched. The harbor master wants to publish an honor roll of every dock that outsold the day's harbor-wide average price, so buyers know which docks commanded a premium.
n, the number of docks that reported a sale.n lines contains a dock name and an integer price, separated by a space.Print one line for every dock whose price is strictly greater than the average price across all n docks (the average is the exact sum of all prices divided by n -- do not round). Each printed line has the format name price. Order the printed docks by price in strictly decreasing order; if two qualifying docks share the same price, order them by name in ascending lexicographic order. If no dock qualifies, print nothing.
Example 1
Input
4 dockA 50 dockB 30 dockC 70 dockD 10
Expected
dockC 70 dockA 50
Explanation
The four prices sum to 160, so the harbor-wide average is 40. dockC (70) and dockA (50) both beat 40, while dockB (30) and dockD (10) do not. Sorted by price descending, dockC (70) comes before dockA (50).
Example 2
Input
3 dockA 20 dockB 20 dockC 20
Expected
(empty)Explanation
All three docks sold at the same price, so the average is exactly 20 and no dock's price is strictly greater than the average -- the correct output is empty.
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 →