#K2296. Maximum Overlapping Bus Trips
Maximum Overlapping Bus Trips
Maximum Overlapping Bus Trips
In this problem, you are given the schedules of bus trips during a day. Each bus trip has a start time and an end time. Your task is to determine the maximum number of buses that are simultaneously on the road at any given moment.
Formally, for a given set of bus trips, where each trip is represented by a pair of integers ( s ) and ( e ) (with ( s < e )), find the maximum value of overlapping intervals at any time instant.
Note: The input contains multiple test cases. A test case starts with an integer ( n ) indicating the number of bus trips. The next ( n ) lines contain two integers each (representing the start and end times, respectively). A test case with ( n = 0 ) indicates the end of input and should not be processed.
inputFormat
The input is provided via standard input (stdin). It consists of multiple test cases.
Each test case begins with an integer ( n ) (( n \ge 0 )). If ( n ) is zero, it indicates the end of input. Otherwise, the following ( n ) lines each contain two space-separated integers ( s ) and ( e ), representing the start and end times of a bus trip.
outputFormat
For each test case, output a single integer on a new line, representing the maximum number of bus trips that are overlapping at any point in time, written to standard output (stdout).## sample
5
300 600
700 1200
500 900
800 1000
100 200
3
120 180
150 210
300 360
0
3
2
</p>