#C9178. Minimum Removals for Strictly Increasing Sequence
Minimum Removals for Strictly Increasing Sequence
Minimum Removals for Strictly Increasing Sequence
Given a sequence of integers representing scores, your task is to determine the minimum number of scores that need to be removed so that the remaining sequence becomes strictly increasing.
Let \(n\) be the number of scores and \(L\) be the length of the longest strictly increasing subsequence. Then the desired answer is computed by the formula:
\[ \text{Answer} = n - L \]
Example: For scores [2, 3, 1, 2, 3]
, we have \(n = 5\) and one of the longest increasing subsequences is [2, 3, 3]
(or alternatively [2, 2, 3]
) with length \(L = 3\). Hence, the minimum removals required is \(5 - 3 = 2\).
You should read input from stdin and write the output to stdout.
inputFormat
The first line contains an integer (n), representing the number of scores. The second line contains (n) space-separated integers denoting the scores.
outputFormat
Output a single integer which is the minimum number of scores to remove to ensure that the remaining scores form a strictly increasing sequence.## sample
5
2 3 1 2 3
2