Apparently the three flight terminals in Mathiland are disorganized and supposed to have two planes on the same runway now but that's obviously not going to happen. Your job is to fix to flight disorganization.
This file
contains a list of the flights and their time of departure in 24 hour time (23:45, 13:59, etc.). You have the option to move the departure times forward or backwards by a maximum of five minutes and the time taken for an airplane to take off and have the runway clear again is 20 minutes. If the runway is occupied 5 minutes before until 5 minutes after the expected takeoff time, the flight will be cancelled.
Given the list, find the maximum number of planes that can take off in that day.
Assumptions
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This problem is quite nice, my code didn't solve the problem on my first try, so since the amount of flights is so small, I decided to use brute-force to search for the answer, and I got it right, but I still tried to fix the bug in my code, and here it is:
I will explain my code.
First, I read all inputs and parse it into my desired format. Then, I sorted them. After sorting, I initialized an array(should be vector) of boolean values to true(I will explain why I do this later), and initialize the variable ans to 0.
Here's what I do next to find the answer:
Check if the flight is available.
Find the time difference and check if it does not overlap the next flight. If it doesn't, add 1 to ans and proceed to the next flight.
Then, I try to move the time forward as many as I can.
Check again if the flight does not overlap the next flight. If doesn't, do the same thing as 2.
Then, I try to delay the flight as far as I can.
Now, check if they overlap. If they overlap, we have no choice but to cancel the next flight.
Add 1 to ans.
If you have any problems with my code, please let me know.