Aeroplanes Scheduling

3.9

8 votes
Algorithms, Dynamic Programming, Dynamic programming, Easy
Problem

There are N aeroplanes scheduled for departure from a runway all arriving at the same destination. All the aeroplanes will depart one by one in the order mentioned which is given by the array S such that the ith element of the array i.e Si gives the constant speed of the ith aeroplane. Aeroplane will maintain this speed throughout its journey. Also, there are only two elevations available for the aeroplanes currently i.e only two heights are permitted for the aeroplanes and for one particular elevation all the aeroplanes must be in a single straight line. Also an aeroplane i​ will be happy​ only if all the aeroplanes in its elevation and ahead of it are moving at a speed greater than or equal to its speed because only then it wouldn’t have to slow its speed during its course of journey. Schedule the aeroplanes so that the number of happy aeroplanes are maximized. Compute this number. (Consider no collision/overtake during the entire journey and assume the source to destination distance to be very very long)


INPUT FORMAT

  • First line consists of a single integer N denoting the number of aeroplanes
  • Next line consists of N space separated integers with ith integer denoting Si , the speed of ith aeroplane

OUTPUT FORMAT

  • Print a single integer denoting the maximum number of happy aeroplanes that can be obtained by some scheduling

CONSTRAINTS

  • 1N5000
  • 1Si109

SUBTASKS

  • For 20 Points : 1N,Si100
  • For 80 Points : Original Constraints
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

One possible optimal shceduling is : Schedule first and second aeroplanes in lane 1. Clearly, first one is happy. Schedule third , fourth , fifth and sixth aeroplanes in lane 2. The third, fourth and fifth aeroplanes are happy. So the final ordering : 

Lane 1 :=  2 3

Lane 2 :=  5 4 1 9

In the above ordering, for lane 1 aeroplane with speed 2 is ahead of aeroplane with speed 3. Similarly for lane 2 also.

Editor Image

?