We are given n-platform and two main running railway track for both direction. Trains which needs to stop at your station must occupy one platform for their stoppage and the trains which need not to stop at your station will run away through either of main track without stopping. Now, each train has three value first arrival time, second departure time and third required platform number. We are given m such trains you have to tell maximum number of train for which you can provide stoppage at your station.
Input : n = 3, m = 6 Train no.| Arrival Time |Dept. Time | Platform No. 1 | 10:00 | 10:30 | 1 2 | 10:10 | 10:30 | 1 3 | 10:00 | 10:20 | 2 4 | 10:30 | 12:30 | 2 5 | 12:00 | 12:30 | 3 6 | 09:00 | 10:05 | 1 Output : Maximum Stopped Trains = 5 Explanation : If train no. 1 will left to go without stoppage then 2 and 6 can easily be accommodated on platform 1. And 3 and 4 on platform 2 and 5 on platform 3. Input : n = 1, m = 3 Train no.|Arrival Time|Dept. Time | Platform No. 1 | 10:00 | 10:30 | 1 2 | 11:10 | 11:30 | 1 3 | 12:00 | 12:20 | 1 Output : Maximum Stopped Trains = 3 Explanation : All three trains can be easily stopped at platform 1.
If we start with a single platform only then we have 1 platform and some trains with their arrival time and departure time and we have to maximize the number of trains on that platform. This task is similar as Activity Selection Problem. So, for n platforms we will simply make n-vectors and put the respective trains in those vectors according to platform number. After that by applying greedy approach we easily solve this problem.
Note : We will take input in form of 4-digit integer for arrival and departure time as 1030 will represent 10:30 so that we may handle the data type easily.
Also, we will choose a 2-D array for input as arr[m] where arr[i] denotes arrival time, arr[i] denotes departure time and arr[i] denotes the platform for ith train.
Maximum Stopped Trains = 3
- Value in a given range with maximum XOR
- Maximum String Partition
- Find the maximum possible value of a[i] % a[j] over all pairs of i and j
- Maximum possible sub-array sum after at most X swaps
- Maximum array sum that can be obtained after exactly k changes
- Choose n elements such that their mean is maximum
- Maximum possible sum after M operations on N cards
- Maximum elements which can be crossed using given units of a and b
- Maximum sum of absolute difference of an array
- Covering maximum array elements with given value
- Given count of digits 1, 2, 3, 4, find the maximum sum possible
- Maximum product subset of an array
- Maximum number of candies that can be bought
- Maximum money that can be withdrawn in two steps
- Minimize the maximum difference between the heights
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.