#K78132. Minimum Removals for Non-decreasing Array

    ID: 35019 Type: Default 1000ms 256MiB

Minimum Removals for Non-decreasing Array

Minimum Removals for Non-decreasing Array

In this problem, you are given an array of integers. Your task is to compute the minimum number of elements to remove so that the remaining array is non-decreasing. Formally, if the array has (n) elements and the length of its longest non-decreasing subsequence is (L), then the answer is (n - L).

You need to implement a solution that reads the input from stdin and outputs the result to stdout.

inputFormat

The input is given from stdin and consists of two lines. The first line contains a positive integer (n) ((1 \le n \le 10^5)), which is the number of elements in the array. The second line contains (n) space-separated integers.

outputFormat

Output a single integer to stdout — the minimum number of removals needed to make the array non-decreasing.## sample

5
3 1 2 4 3
2

</p>