#abc352d. D - Permutation Subsequence
D - Permutation Subsequence
Score: points
问题陈述
给定一个排列 ,它是 的一个排列。
如果一个长度为 的索引序列 满足以下两个条件,则称其为一个好索引序列:
- 。
- 子序列 可以通过重新排列某些连续的 个整数获得。 形式上,存在一个整数 使得 $\lbrace P_{i_1},P_{i_2},\dots,P_{i_K} \rbrace = \lbrace a,a+1,\dots,a+K-1 \rbrace$。
在所有好索引序列中,找到 的最小值。可以证明,在这个问题的约束条件下,至少存在一个好索引序列。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a permutation of .
A length- sequence of indices is called a good index sequence if it satisfies both of the following conditions:
- .
- The subsequence can be obtained by rearranging some consecutive integers.
Formally, there exists an integer such that $\lbrace P_{i_1},P_{i_2},\dots,P_{i_K} \rbrace = \lbrace a,a+1,\dots,a+K-1 \rbrace$.
Find the minimum value of among all good index sequences. It can be shown that at least one good index sequence exists under the constraints of this problem.
Constraints
- if .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the minimum value of among all good index sequences.
Sample Input 1
4 2
2 3 1 4
Sample Output 1
1
The good index sequences are . For example, is a good index sequence because and is a rearrangement of two consecutive integers .
Among these good index sequences, the smallest value of is for , which is .
Sample Input 2
4 1
2 3 1 4
Sample Output 2
0
in all good index sequences.
Sample Input 3
10 5
10 1 6 8 7 2 5 9 3 4
Sample Output 3
5