Part Rental Log
InterviewTime limit1sMemory limit512 MB
Parse a chronological log of borrow and return events, match them per person and part, and sum fines for rentals that exceed the allowed period, then print nicknames in lexicographic order.
- Level
Medium6 of 10
- Topics
- Hash map, String, Simulation, Implementation
- Solved
- No attempts yet
Problem
Songhun is a member of a robot club. When the robot club needs a part, members may freely borrow it, use it, and return it.
While organizing the parts, Songhun found part management too difficult, so the club is introducing a new system.
When borrowing a part, a member must write the information in the part rental log. When returning a borrowed part, the member must also write the information in the part rental log.
The system also sets a rental period, and if the period is exceeded, it charges a fine per minute.
Suppose the rental period is 5 minutes and the fine is 5 won per minute. If a part is borrowed at 1:05 on January 1, 2021, it must be returned by 1:10 on January 1, 2021.
If it is returned at 1:14 on January 1, 2021, that is 4 minutes late, so the fine is 20 won.
The format written in the part rental log is as follows.
yyyy-MM-dd hh:mm [part name] [club member nickname]
Below is information written in the part rental log as an example. Assume the rental period is 5 minutes and the fine is 1 won.
2021-01-01 09:12 arduino tony9402
2021-01-01 09:13 monitor chansol
2021-01-01 09:18 arduino tony9402
2021-01-01 09:18 monitor chansol
Summarizing the information above gives the following.
tony9402 borrowed arduino at 9:12 AM on January 1, 2021.
chansol borrowed monitor at 9:13 AM on January 1, 2021.
tony9402 returned arduino at 9:18 AM on January 1, 2021.
chansol returned monitor at 9:18 AM on January 1, 2021.
tony9402 returned it 1 minute late, so the fine is 1 won.
The following conditions must hold when renting parts.
- A person cannot be in a state of having borrowed two or more parts of the same kind.
- A person can borrow different kinds of parts at the same time.
- Even for the same person, the rental period applies separately to each part.
Input
The first line gives the number of entries in the part rental log, the rental period , and the fine , separated by spaces.
The rental period format is DDD/hh:mm, where DDD is days, hh is hours, and mm is minutes. (000/00:00 is not given.)
From the second line to the -th line, entries in the part rental log (time, part name , member nickname ) are given in chronological order, separated by spaces.
The time format is yyyy-MM-dd hh:mm, where yyyy is the year, MM is the month, dd is the day, hh is hours, and mm is minutes. In this problem, the year in the input is always 2021.
The part name consists only of lowercase alphabet letters. That is, a part name contains no spaces.
The member nickname consists only of lowercase alphabet letters and digits ~ . That is, a member nickname contains no spaces.
Output
Print the club member nicknames of the people who must pay a fine and the fine they must pay, one line each, in lexicographic order.
If there is no one who must pay a fine, print -1.
Constraints
- , is even
- No one fails to return a part.