In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of January 4th
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #12 exercise sheet]
Your company runs an auction of rare Pókemon cards. The auction works as follows:
An example of an auction would be as follows:
Given the events of an auction, your task is to find out the buyer for each of the sold cards.
The first line contains N, the number of events. This is followed by N lines, each of which describes an event, containing "SALE" if someone has decided to sell a card, or "OFFER namei pricei" if it's an offer to buy a card for pricei by person namei (the name is a letter only string and the price is an integer).
The output should be made up of as many lines as there are occurrences of the word SALE in the input. On each of these lines, which come in the order of the sales, should be the price and the name of the buyer of the respective sale, separated by a space.
It is guaranteed that when someone wants to sell there is always at least one offer and that there are no ties (there is always someone with a maximum price).
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ N ≤ 100 000 | Number of events | |
1 ≤ |namei| ≤ 20 | Length of each name | |
1 ≤ pricei ≤ 1 000 000 | Offer prices |
Example Input | Example Output |
7 OFFER John 20 OFFER Mary 35 OFFER Rachel 15 SALE OFFER Sarah 42 SALE SALE |
35 Mary 42 Sarah 20 John |
Explanation of Example Input
The example input is explained in the problem statement.