Score : $500$ points
Let us define $\mathrm{mex}(x_1, x_2, x_3, \dots, x_k)$ as the smallest non-negative integer that does not occur in $x_1, x_2, x_3, \dots, x_k$.
You are given an integer sequence of length $N$: $A = (A_1, A_2, A_3, \dots, A_N)$.
For each integer $i$ such that $0 \le i \le N - M$, we compute $\mathrm{mex}(A_{i + 1}, A_{i + 2}, A_{i + 3}, \dots, A_{i + M})$. Find the minimum among the results of these $N - M + 1$ computations.
Input is given from Standard Input in the following format:
$N$ $M$ $A_1$ $A_2$ $A_3$ $\dots$ $A_N$
Print the answer.
3 2 0 0 1
1
We have:
Thus, the answer is the minimum among $1$ and $2$, which is $1$.
3 2 1 1 1
0
We have:
3 2 0 1 0
2
We have:
7 3 0 0 1 2 0 1 0
2