GFSSOC '15 Winter J3 - Christmas Presents

View as PDF

Submit solution

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 P presents, each present i with a unique price value C_i (0 \le C_i \le 2 * 10^{10}). Fardin has T (2 \le T \le P \le 20) teachers who he likes, each teacher j with a unique rating of T_j (1 \le T_j \le 100). 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 T 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, P

Line 2: one integer, T

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

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

The next 2T 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.


Comments

There are no comments at the moment.