DWITE
December 2011
Problem 1
Weighted Presents

This non-discriminatory year-end holiday season you have received a present. It has to stay neatly wrapped for some time, but you want to know what it is now. Estimating the weight of the package, and the weights of possible presents, pick the closest match.

The input file DATA1.txt will contain 5 test cases, each 5 lines long. The first line will be an integer value, the weight of the package. The following 4 lines will possible choices, each in form: name weight, where name is a single word and weight is an integer weight for this choice.

The output file OUT1.txt will contain 5 lines of output, each name of the closest guess out of the choices. If two items tie, then answer with the heavier of the two.

Sample Input (first 2 cases):
 
-2
helium -3
air 0
socks 1
brick 10
4
brick 10
books 7
socks 1
air 0
		        
Sample Output (first 2 cases):
 
helium
books