Mock CCC '14 J4 - Selecting Shifts

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem type
2014 Mock CCC by Alex and Timothy

Alice figured out where Bob works, and has obtained a job there so she can secretly admire him at work. Because she is new, the position is only part-time, and she is always called in to shifts by her boss. Whenever this happens, she is offered various shifts to pick from, starting and ending at different times of the day. Alice knows that Bob works from T_1 to T_2 on days that she's called in.

Alice's employer has given her a list of the shifts that she can choose from in order of decreasing pay. Given this list, Alice would like to know which one would result in the longest period of time that both of them are simultaneously on the job. If multiple shifts yield the same time spent with Bob, she would like to know the highest paying out of those (i.e. the one that appears earliest in the list).

Input Specification

Line 1 contains T_1 and T_2, the time that Bob starts and ends his shift.
Line 2 contains the integer N (1 \le N \le 100), the number of shifts that Alice is being offered.
The next N lines each contain two times — the start and end times of that shift. The shifts are ordered by decreasing pay.

Times in the input will be in the 7 character long format as depicted in the sample input below, and will all describe times within the same 24 hour day (between 12:00AM and 11:59PM, inclusive). Every shift described will have the start time strictly before the end time.

Output Specification

The start and end time of the shift that Alice should pick to maximize the time she gets to spend on the job with Bob. If there are multiple answers, pick the one that is higher up on the list. If none of the shifts overlap with Bob's shift, output Call in a sick day., since Alice has no interest in wasting her time at work when Bob is not there.

Sample Input

10:30AM 07:00PM
4
05:30AM 10:00AM
11:00AM 08:15PM
01:45PM 05:00PM
08:00PM 11:00PM

Sample Output

11:00AM 08:15PM

Explanation

Bob works from 10:30AM to 7:00PM. If Alice picks the shift from 1:45PM to 5:00PM, she will spend 3 hours and 15 minutes on the job with Bob. If Alice picks the shift from 11:00AM to 8:15PM, she will spend 8 hours on the job with Bob (from 11:00AM to 7:00PM, when Bob gets off). The shift from 5:30AM to 10:00AM ends before Bob even goes in to work, and the shift at 8:00PM starts after Bob has already left.


Comments


  • 0
    Orion222  commented on Aug. 29, 2024, 7:07 p.m.

    hint for testcase 3?


    • 0
      ev_code  commented on Nov. 10, 2024, 10:21 p.m.

      Make sure to account for the fact that 12:00AM is midnight (0:00) and 12:00PM is noon.

      Remember that 12:00PM is earlier than times like 1:00PM and same thing for AM.

      Hope this helps!