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
- Maximum Length Chain of Pairs | DP-20
- Minimize the maximum difference between the heights
- Find maximum sum possible equal sum of three stacks
- Find maximum height pyramid from the given array of objects
- Find the minimum and maximum amount to buy all N candies
- Maximum score after flipping a Binary Matrix atmost K times
- Buy Maximum Stocks if i stocks can be bought on i-th day
- Split n into maximum composite numbers
- Pair formation such that maximum pair sum is minimized
- Partition into two subarrays of lengths k and (N - k) such that the difference of sums is maximum
- Divide cuboid into cubes such that sum of volumes is maximum
- Maximum number of customers that can be satisfied with given quantity
- Maximum sum of increasing order elements from n arrays
- Maximum elements that can be made equal with k updates
- Maximum sum of absolute difference of an array
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.