[ABC352D] 连续值域下标跨度 (Permutation Subsequence)
Score: points
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:
$N$ $K$
$P_1$ $P_2$ $\dots$ $P_N$
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