#K69132. Minimum Removals to Achieve a Strictly Increasing Sequence

    ID: 33019 Type: Default 1000ms 256MiB

Minimum Removals to Achieve a Strictly Increasing Sequence

Minimum Removals to Achieve a Strictly Increasing Sequence

You are given an array of N integers and an integer K representing the maximum number of removals allowed. Your task is to calculate the minimum number of removals needed to transform the array into a strictly increasing sequence.

Let \(\text{LIS}\) be the length of the longest increasing subsequence in the array. The minimum removals needed is \(N - \text{LIS}\). If \(N - \text{LIS} \le K\), then output \(N - \text{LIS}\); otherwise, output \(-1\) because it is impossible within the allowed removals.

Note: The sequence must be strictly increasing, i.e. each element must be greater than the previous one.

inputFormat

The input is given in two lines:

  • The first line contains two integers \(N\) and \(K\), where \(N\) is the number of elements in the sequence and \(K\) is the maximum allowed number of removals.
  • The second line contains \(N\) space-separated integers representing the sequence.

outputFormat

Print a single integer: the minimum number of removals required to obtain a strictly increasing sequence. If it is not possible to achieve such a sequence within \(K\) removals, print -1.

## sample
6 3
5 3 4 2 6 1
3