#K56772. Minimum Books Removal

    ID: 30273 Type: Default 1000ms 256MiB

Minimum Books Removal

Minimum Books Removal

You are given a sequence of book heights. Your task is to determine the minimum number of books that must be removed so that the remaining sequence of book heights is strictly increasing.

This problem can be modeled as finding the length of the longest strictly increasing subsequence (LIS) in the list of heights. Once the length of the LIS is determined, the minimum number of removals is computed by subtracting the length of the LIS from the total number of books.

Note: The underlying approach utilizes a binary search technique to efficiently compute the LIS in O(n log n) time.

inputFormat

The first line of input contains an integer n, the number of books. The second line contains n space-separated integers representing the heights of the books.

outputFormat

Output a single integer representing the minimum number of books to remove so that the sequence of remaining book heights is strictly increasing.## sample

6
5 3 4 8 6 7
2

</p>