#K751. Minimum Railway Platforms
Minimum Railway Platforms
Minimum Railway Platforms
The task is to determine the minimum number of railway platforms required for a train station so that no train needs to wait. Given two arrays representing the arrival and departure times of the trains, you need to compute the minimum number of platforms required at any time.
Formally, let \(A = [a_1, a_2, \dots, a_n]\) and \(D = [d_1, d_2, \dots, d_n]\) be the arrival and departure times respectively. You are to find the minimum integer \(P\) such that at any time \(t\), the number of trains that have arrived but not yet departed is \(\leq P\).
Note: The arrival and departure times are given in a 24-hour format without any separators (e.g. 900 for 9:00 AM, 1800 for 6:00 PM).
inputFormat
The input is given from the standard input (stdin) and consists of three lines:
- An integer \(n\) representing the number of trains.
- \(n\) space-separated integers representing the arrival times of the trains.
- \(n\) space-separated integers representing the departure times of the trains.
For example:
6 900 940 950 1100 1500 1800 910 1200 1120 1130 1900 2000
outputFormat
Output a single integer to the standard output (stdout) which denotes the minimum number of platforms required so that no train waits.
For the input example above, the correct output is:
3## sample
6
900 940 950 1100 1500 1800
910 1200 1120 1130 1900 2000
3