Senior, Please Buy Me Dinner!
Time limit1sMemory limit1024 MB
Given each senior's promised week, day, and dinner cost plus their money, find the longest run of consecutive days with a promise the senior can afford to pay.
- Level
Easy3 of 10
- Topics
- Sorting, Hash map, Implementation
- Solved
- No attempts yet
Problem
Jeongmin, a freshman in the class of 2024, writes down every dinner promise his seniors made in a notepad. Each line of the notepad records a senior's name , the promise week , the day , and the cost of the dinner. Names are strings, and the rest are integers. Also, no senior buys dinner more than once, and all senior names are different.
Being a computer science major, Jeongmin writes the day as an integer between and . For example, Monday is and Thursday is .
Kind seniors cannot back out of a dinner promise to their cute junior if they have enough money to pay for it. Looking at Jeongmin's records and the money each senior has, find the maximum number of consecutive days on which Jeongmin can get a free dinner.
Input
The first line contains the number of records . ()
From the second line, the next lines each contain record information in the form , which means senior made a dinner promise on day of week that costs won. Each senior name appears exactly once in the records. (; ; )
Then, the next lines each contain a senior name and the money that senior has, separated by a space. The order of the names here may differ from the order in the records. ()
Each senior name is a string of up to 12 English letters, uppercase or lowercase.
Output
Print the maximum number of consecutive days on which Jeongmin can get a free dinner.
Hint
By international standard, the week starts on Monday.