bzoj#P3927. [NEERC2014] Improvements
[NEERC2014] Improvements
Description
Son Halo owns spaceships numbered from to and a space station. They are initially placed on one line with the space station so the spaceship is positioned meters from the station and all ships are on the same side from the station . All are distinct. Station is considered to have number and is considered to be equal to .
Every two spaceships with consequent numbers are connected by a rope, and the first one is connected to the station. The rope number (for ) connects ships and . Note, that the rope number connects the first ship to the station.
Son Halo considers that the rope and the rope intersect when the segments and have common internal point but neither one of them is completely contained in the other, where $x_k^{\min}=\min\{x_{k-1},x_k\},x_k^{\max}=\max\{x_{k-1},x_k\}$. That is:
$$\begin{cases} x_i^{\min}< x_j^{\min}\land x_j^{\min}< x_i^{\max}\land x_i^{\max}< x_j^{\max}\\ x_j^{\min}< x_i^{\min}\land x_i^{\min}< x_j^{\max}\land x_j^{\max}< x_i^{\max} \end{cases} $$Son Halo wants to rearrange spaceships in such a way, that there are no rope intersections. Because he is lazy, he wants to rearrange the ships in such a way, that the total number of ships that remain at their original position is maximal. However, ships can occupy any real positions after rearrangement.
Your task is to figure out what is the maximal number of ships that can remain at their initial positions.
Input Format
The first line of the input file contains - the number of ships. The following line contains distinct integers - the initial positions of the spaceships.
Output Format
The output file must contain one integer - the maximal number of ships that can remain at their initial positions in the solution of this problem.
4
1 3 2 4
3
4
1 4 2 3
4
Limit and Hint
For of testcases, , .
In the first sample Son Halo can remove the second spaceship in the position between the first and the third to solve the problem while keeping other ships at their initial positions.
In the second sample there are no rope intersections, so all ships can be left at their initial positions.
Source
ACM ICPC 2014-2015, NorthEastern European Regional Contest, Problem I