Editorial for TLE '16 Contest 5 P3 - Flight Exam


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: ZQFMGB12

First, we note that there are up to 2N significant points that Fax can visit: all N checkpoints, and all points that are S meters below a checkpoint. If S=0 or the point has a negative altitude, we ignore the second point. For each point, we store the number of checkpoints Fax gains if he passes through this point. As such, each point will either have a value of 1 (checkpoint with nothing above, empty point with checkpoint above) or 2 (checkpoint with checkpoint above). For the i^{th} point, let this value be v_i.

Next, we can use dynamic programming to compute the answer. For each point, we want to know the maximum number of checkpoints Fax could have passed through after going through the current point and performing a loop. For the i^{th} point, let this value be a_i. We can see that a_i = \max(a_j + v_i) for all points j with a distance less than point i that can be reached by ascending or descending.

The answer is the maximal a_i.

Time Complexity: \mathcal{O}(N^2)


Comments

There are no comments at the moment.