cswork / OA打开练习工作台

HackerearthOA #1

Happy Neighbourhood

估计中等可在线判题

考点(AI 标注)并查集原地数组

Houses are numbered 1..N, and people move in one house at a time in the order of the given permutation. Find the earliest day on which some contiguous segment of M houses is fully occupied.

输入格式

The input contains N, M and a permutation of length N. 1≤N≤100000, 1≤M≤N.

输出格式

Output the day on which a fully occupied contiguous segment of length M first appears.

样例 1

输入:

3
1
3 2 1

输出:

1

样例 2

输入:

10
8
8 4 9 10 3 1 7 2 6 5

输出:

10

样例 3

输入:

20
2
16 12 14 7 11 13 15 4 1 20 9 3 10 8 6 2 17 19 18 5

输出:

5