Bus Terminal
InterviewTime limit1sMemory limit1024 MB
Given N bus arrival and departure times, find the minimum number of service spaces so that no bus ever has to wait, with departures processed before simultaneous arrivals.
- Level
Medium4 of 10
- Topics
- Sorting, Intervals, Greedy, Implementation
- Solved
- No attempts yet
Problem
Buses that have finished their routes arrive at the terminal. A bus that arrives at the terminal enters a spot where it is serviced. That is, if 4 buses are at the terminal, at least 4 spaces for servicing buses are needed. If bus A is arriving at the terminal and bus B is departing the terminal at the same time, bus B departs first, and then bus A arrives.
The bus timetable is the same every day, and the arrival and departure times at the terminal are the same every day.
The bus timetable has now changed, so the minimum number of spaces needed to service buses must be recalculated. Help with this calculation.
Input
The first line gives the number of buses arriving at the terminal.
From the second line to the -th line, the arrival time and departure time of each bus are given. A bus's departure time is later than its arrival time.
Times are given in the format HH:MM:SS.sss, where HH is hours, MM is minutes, SS is seconds, and sss is milliseconds.
Output
Output the minimum number of spaces needed to service buses.