cswork / OA打开练习工作台

AmazonOA #278

Maximum Possible Racers

估计中等可在线判题

考点(AI 标注)双指针滑窗哈希计数

Remove at most k racers; everyone else keeps their original relative order. Find the maximum number of people in a contiguous same-speed segment of the remaining line. Output the number of people who stay in that segment, not counting removed racers.

输入格式

The first line contains n k and the second line contains speed. On this site 1≤n≤200000, 0≤k≤n, 1≤speed[i]≤10^9. The original index typo "0 to n" is unified as 0..n−1 for n items.

输出格式

Output a single integer, the answer.

样例 1

输入:

5 1
1 2 1 2 1

输出:

2

样例 2

输入:

4 0
3 3 4 3

输出:

2

样例 3

输入:

3 3
1 2 3

输出:

1

样例说明

The answers are 2, 2 and 1 respectively. In the first example, removing only one 2 is still not enough to connect the three 1s.