#K86617. Maximum Trains at Station
Maximum Trains at Station
Maximum Trains at Station
You are given a list of train schedules represented as arrival and departure times in the format HH:MM
. Your task is to determine the maximum number of trains present at the station at any given moment.
The approach is based on event processing. For each train, an arrival event and a departure event are recorded. When sorting events, in the case of a tie, the arrival event is considered before the departure event. Mathematically, if we denote the arrival time of a train by \(A_i\) and its departure time by \(D_i\), then the problem is to compute: \[ \max_{t}\left(\sum_{i} \mathbf{1}_{\{A_i \le t < D_i\}}\right) \]
The input is read from stdin and the output is written to stdout.
inputFormat
The first line contains a positive integer N
, the number of trains. Each of the following N
lines contains two strings representing the arrival time and departure time of a train in the format HH:MM
, separated by a space.
Example Input:
3 10:00 10:30 10:15 10:45 10:40 11:00
outputFormat
Output a single integer representing the maximum number of trains that are simultaneously at the station.
Example Output:
2## sample
3
10:00 10:30
10:15 10:45
10:40 11:00
2