#K76327. Minimum Students to Remove
Minimum Students to Remove
Minimum Students to Remove
You are given a line of students represented by an array of their heights. Your task is to remove the minimum number of students so that the heights of the remaining students form a strictly increasing sequence.
This problem can be formulated as follows: given an array H of n integers, find the value of
where L is the length of the longest strictly increasing subsequence (LIS) of H. In a strictly increasing sequence, each element is strictly greater than the previous one. You need to compute the minimum removals required to achieve this.
Example: For the input [4, 3, 2, 6, 5, 8, 7], the longest strictly increasing subsequence is [4, 6, 8] (or a similar variant) having length 3. Therefore, the minimum number of removals is 7 - 3 = 4.
inputFormat
The input is given in two lines from stdin. The first line contains a single integer n (the number of students). The second line contains n space-separated integers representing the heights of the students.
Note: The input will always be valid.
outputFormat
Output a single integer to stdout which represents the minimum number of students that need to be removed to ensure that the remaining students are in strictly increasing order by height.
## sample7
4 3 2 6 5 8 7
4
</p>