Hide

Problem B
Enduro

There is an epic enduro race taking place around the lake Sjön sjön at LTH. The race lasts for 3 hours, and the goal is to complete as many laps as possible within this time. Whenever a participant passes the lap line before the end of the race, they need to start another lap. The participants finish their race when they pass the lap line at or after the time limit (3 hours from the starting time). Some participants might do one or several extra laps after finishing the race but these laps do not count towards the race result.

During the race, the times at which participants pass the lap line are recorded (this does not include the time when they start), and after the race this information will be used to construct a rank list of all participants.

The participants are first ranked by the number of laps they completed, with participants having completed more laps being ranked higher. If multiple participants have completed the same number of laps, they are then ranked by the time that they finished their final lap, with earlier times being ranked higher. The race organizers have not considered how participants should be ranked if they finish the same number of laps in exactly the same amount of time, but that will probably not happen.

If a participant starts a lap but doesn’t finish it they get a DNF (did not finish) and are not included in the rank list.

A program for generating the rank list has been in development for the past couple of months by a team of second year computer science students. Unfortunately, the program appears to be highly unstable, and after inputting more than 20 entries consumes more memory than available on any of the computers owned by the race organizers.

The race is starting soon and the race organizers need your help with writing a replacement program.

Input

The first line of input contains the starting time of the race, formatted as “HH:MM:SS AM/PM” where “HH” is an integer between $1 — 12$, “MM” and “SS” are integers between $0 — 59$, and “AM/PM” is either the string AM or PM depending on whether the time is before or after noon. Midnight would be written “12:00:00 AM”, and noon would be written “12:00:00 PM”.

The first line contains one integer $N$ ($1 \leq N \leq 10,000$), the number of timestamps recorded.

The following $N$ lines contain a timestamp in the same format as the start time, followed by a space, followed by the name of the contestant passing the lap line at that time. Contestant names consist of $1$ to $20$ characters, which can be uppercase and lowercase letters “A” to “Z” and space. Names will not contain more than one space, and they will not begin or end with a space.

The timestamps are sorted in ascending order, and it is guaranteed that no two timestamps are at exactly the same time. All timestamps are also guaranteed to be within $6$ hours of the starting time (but not necessarily on the same day as the starting time).

Output

Output one line per participant that did not get a DNF, ordered according to the ranking rules described above, with the highest ranked participant listed first. Each line should contain the number of laps completed by that participant, followed by a space, followed by the participant’s name.

Scoring

Group

Points

Limits

Satisfied by Sample(s)

1

19

No two participants complete the same number of laps, and each participant passes the lap line exactly once on or after the time limit

2

2

14

No two participants complete the same number of laps

2

3

35

The start time is “01:00:00 PM

1

4

32

No additional constraints

1 and 2

Sample Input 1 Sample Output 1
01:00:00 PM
6
01:14:10 PM Bjorn Magnusson
03:59:59 PM Pusheen
04:00:00 PM Bjorn Magnusson
04:58:50 PM Erik
05:23:09 PM Thore
05:44:38 PM Erik
2 Bjorn Magnusson
1 Erik
1 Thore
Sample Input 2 Sample Output 2
10:36:19 PM
6
10:52:10 PM Thore
11:02:56 PM Thore Husfeldter
12:18:01 AM Thore Husfeldter
01:36:19 AM Pusheen
01:55:23 AM Thore
04:05:53 AM Thore Husfeldter
3 Thore Husfeldter
2 Thore
1 Pusheen

Please log in to submit a solution to this problem

Log in