## GFSSOC '15 Winter J3 - Christmas Presents

View as PDF

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 32M

Authors:
Problem type

Now that Fardin has bought his presents, he must distribute them amongst his teachers. However, he is doing well with some teachers and poorly with some others. Fardin has bought presents, each present with a unique price value . Fardin has teachers who he likes, each teacher with a unique rating of . However, he is too lazy to determine the distribution so he decides to ask you to code a program for him. Fardin would like to assign the least expensive presents he bought. His least favourite teacher should receive the least expensive present, his second least favourite teacher should receive the second least expensive present, etc. See the sample input for clarification.

#### Input Specification

Line 1: one integer,

Line 2: one integer,

The next lines describe the presents and will be in the following form:

• Present name
• Present price (Given to 2 decimal places)

The next lines describe the teachers and will be in the following form:

• Teacher name
• Teacher rating (Given as an integer)

Note: The input may contain spaces, punctuation, lowercase and uppercase letters.

#### Output Specification

The teacher and the present they get in ascending order of Fardin's unique rating of them.

#### Sample Input

4
4
Compact Disc
2.50
Science Textbook
41.50
Chocolate Bar
0.99
Blu-ray Player
25.98
Mr. Nikoletos
93
Ms. Brown
90
Mr. Fong
92
Mr. Wilson
95

#### Sample Output

Ms. Brown will get a Chocolate Bar
Mr. Fong will get a Compact Disc
Mr. Nikoletos will get a Blu-ray Player
Mr. Wilson will get a Science Textbook

#### Explanation

Fardin loves Mr. Wilson the most, thus he gets the most expensive present, the Science Textbook. Next is Mr. Nikoletos, so he'll get the second most expensive present, the Blu-ray player, and so on (Why is a textbook more expensive than a Blu-ray player?). We output these in reverse as required by the problem statement.