cswork / OA打开练习工作台

MetaOA #5

Longest Subarray With Value Frequency > Threshold

估计中等可在线判题

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

Find the longest contiguous subarray in which at least one value occurs strictly more than the threshold k times. If none exists, output 0. The check here follows the statement's "strictly greater"; both of the original site's examples should give the full array length 7, and this site has corrected them.

输入格式

The first line contains n k (1≤k≤n≤100000), and the second line contains n values (0..10⁹).

输出格式

Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.

样例 1

输入:

7 3
1 1 1 2 3 1 1

输出:

7

样例 2

输入:

7 1
1 2 3 2 3 4 1

输出:

7

样例 3

输入:

2 2
1 1

输出:

0

样例说明

Example 1: in the full array, 1 occurs 5 times, strictly more than the threshold 3, so the full length 7 is valid and optimal.