Train Timetable (Small)
InterviewTime limit5sMemory limit512 MB
Given a day's timetable and a turnaround time, find the minimum number of trains that must start the day parked at each of the two stations.
- Level
Medium4 of 10
- Topics
- Greedy, Sorting, Simulation, Implementation
- Solved
- No attempts yet
Problem
A railway line has two stations, station A and station B.

Trains may run several times a day from A to B, or from B to A. When a train arrives at B from A (or at A from B), it needs a turnaround time before it can leave again in the opposite direction. For example, if a train arrives at 12:00 and the turnaround time is 0 minutes, that train can leave the station right at 12:00.
The timetable lists the departure time and the arrival time of every train that runs between A and B. The railway company needs to know how many cars to park at A and at B before the day starts so that the timetable can be kept. A train can leave a station only if a car is ready to depart there. A ready car is either a car parked at that station before the day starts, or a car that arrived at that station from the other station and has completed its turnaround time.
The track between the two stations has a passing loop, so trains do not have to arrive in the same order they departed. No train other than the ones written in the timetable runs at all.
Find the minimum number of cars that must be parked at station A and the minimum number of cars that must be parked at station B in order to follow the timetable exactly.
Input
The first line holds the number of test cases .
Each test case spans several lines. Its first line holds the turnaround time in minutes. The next line holds the number of trains from A to B, , and the number of trains from B to A, , separated by a space. The following lines each describe one train from A to B, and the lines after them each describe one train from B to A.
Each train line holds a departure time and an arrival time in HH:MM format, separated by one space. Every train departs earlier than it arrives, and every departure and arrival happens within the same single day. Hours and minutes are both written with two digits, padded with 0, on a 24 hour clock from 00:00 to 23:59.
Constraints
Output
For each test case, print one line in the format Case #x: a b. Here is the test case number starting from 1, is the minimum number of cars to park at station A before the day starts, and is the same number for station B. Separate and with one space.