Birthday Memorization
InterviewTime limit1sMemory limit1024 MB
Given friends with distinct like-scores and birthdays, keep only the highest-scoring friend for each date and print the survivors' names in alphabetical order.
- Level
Easy3 of 10
- Topics
- Hash map, Sorting, Implementation, String
- Solved
- No attempts yet
Problem
Krarkl wants to memorize the birthdays of all of his friends so that every day he knows whom to congratulate. Unfortunately, collisions often occur, meaning several friends have their birthday on the same day. This confuses Krarkl, so he decides that for each date with a collision he will only remember the birthday of the friend he likes the most. Given a list of each friend's birthday and how much Krarkl likes the friend, output which friends Krarkl will remember the birthday of.
Input
The first line of input contains the integer (), the number of friends.
Then follow lines, one for each friend. The th line consists of a string with the th friend's first name, ( is between 1 and 10 characters long), an integer () that says how much Krarkl likes the friend, and the friend's birthday in the format DD/MM (where DD is a day between 01 and 31 and MM is a month between 01 and 12). A higher value of means Krarkl likes the friend more.
The birthdays will be real dates during 2020 (a leap year), e.g. 28/02 for the twenty-eighth of February. The names will consist of only lowercase English letters (a-z), with an uppercase first letter (A-Z). All will be distinct.
Output
You shall output a line with an integer , the number of friends whose birthday Krarkl will remember.
It shall be followed by lines with one word each, the first names of the selected friends, in alphabetical order.
Hint
In the first example, Sanna and Simon have the same birthday. Since Krarkl likes Sanna less than Simon (), Krarkl will only remember Simon's and Saga's birthdays.
In the second example, Krarkl has terrible luck and will miss half of his friends' birthdays.