This page is still under construction.

Parts of this page are still being built. What you see may change.

Part Rental Log

Interview

Time limit1sMemory limit512 MB

Summary
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.

  1. A person cannot be in a state of having borrowed two or more parts of the same kind.
  2. A person can borrow different kinds of parts at the same time.
  3. Even for the same person, the rental period applies separately to each part.

Input

The first line gives the number of entries NN in the part rental log, the rental period LL, and the fine FF, 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 N+1N + 1-th line, entries in the part rental log (time, part name PP, member nickname MM) 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 PP consists only of lowercase alphabet letters. That is, a part name contains no spaces.

The member nickname MM consists only of lowercase alphabet letters and digits (0(0 ~ 9)9). That is, a member nickname contains no spaces.

Output

Print the club member nicknames MM 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

  • 2≤N≤80,0002 \le N \le 80,000, NN is even
  • 0≤DDD≤2000 \le DDD \le 200
  • 1≤MM≤121 \le MM \le 12
  • 0≤hh≤230 \le hh \le 23
  • 0≤mm≤590 \le mm \le 59
  • 1≤F≤4,0001 \le F \le 4,000
  • 5≤∣P∣,∣M∣≤205 \le |P|, |M| \le 20
  • No one fails to return a part.

Examples3

  1. Example 1

    Input
    8 014/00:00 5
    2021-01-01 09:12 arduino tony9402
    2021-01-13 13:24 arduino tony9402
    2021-01-23 14:04 raspberrypi tony9402
    2021-02-01 18:21 resistance amsminn
    2021-02-03 23:14 transistor codethinking
    2021-02-08 22:14 transistor codethinking
    2021-02-09 12:45 resistance amsminn
    2021-02-13 14:37 raspberrypi tony9402
    
    Expected output
    tony9402 50565
    
  2. Example 2

    Input
    4 015/00:00 5
    2021-01-01 09:12 arduino tony9402
    2021-01-13 13:24 arduino tony9402
    2021-02-15 12:12 raspberrypi q540jh
    2021-02-15 12:13 raspberrypi q540jh
    
    Expected output
    -1
    
  3. Example 3

    Input
    4 000/00:05 1
    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
    
    Expected output
    tony9402 1