Auction
InterviewTime limit2sMemory limit128 MB
Given a sequence of bids, find the least-frequent price (lowest if tied) and output the name of the first bidder who offered that price.
- Level
Easy3 of 10
- Topics
- Hash map, Implementation, Sorting
- Solved
- No attempts yet
Problem
Several people want to buy one item, and each participant submits the price they are willing to pay. In a usual auction, the item is sold to the person who offered the highest price. In some auction variants, however, lower prices are preferred.
If the lowest price always won, everyone could simply offer the minimum amount. To avoid that, prices offered by many people are treated as less competitive. The winner is chosen by the following rules.
First, among all offered prices, find the price that was offered by the fewest people. If there are several such prices, choose the lowest one. Finally, among the people who offered the chosen price, the person who submitted that price earliest wins the item.
Given each participant's name and offered price in submission order, determine the winner's name and winning price.
Input
The first line contains two integers U and N. U is the maximum allowed price, and N is the number of bids.
1 ≤ U ≤ 10,0001 ≤ N ≤ 100,000
Each of the next N lines contains a name S and a price P, in the order the bids were submitted.
Sconsists of uppercase and lowercase English letters with no spaces and has length at most 10.1 ≤ P ≤ UPis an integer.
Output
Print the winner's name and the winning price on one line, separated by a space.