All problems

A Pie Chart Next to a Detail Bar Chart

mediumPythonMatplotlibCombined Charts

Kestrel Freight's cost review shows a share-of-spend chart for the top-level cost centres, with a second panel breaking the biggest one into its own subheadings. The reviewer needs two lines of text next to it: which cost centre is the biggest, and what the subheadings add up to — because if that sum does not match the centre's own figure, the breakdown is incomplete and the whole panel is misleading.

Task: Print the largest cost centre and the total of the breakdown.

Input

Four parts. The first line holds one integer n, the number of cost centres. Each of the next n lines holds a cost centre name and its figure, separated by a single space. Then one line holds an integer k, the number of subheadings. Each of the next k lines holds a subheading name and its figure. Names contain no spaces.

Output

Two lines. The first is the name of the cost centre with the largest figure, exactly as it was read. The second is the total of the k subheading figures, as a plain number — a whole total prints with one decimal place, like 70.0. If two cost centres tie, print whichever appeared first.

Example:

Input:
2
Eng 70
Sales 30
2
Backend 40
Frontend 30

Output:
Eng
70.0

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

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…