3862: Longest Subarray

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:1 解决:1

题目描述

You are given two integers C,K and an array of N integers a1,a2,...,aN. It is guaranteed that the value of ai is between 1 to C.

We define that a continuous subsequence al,al+1,...,ar(l≤r) of array a is a good subarray if and only if the following condition is met:

∀x∈[1,C],∑i=lr[ai=x]=0or∑i=lr[ai=x]≥K


It implies that if a number appears in the subarray, it will appear no less than K times.

You should find the longest good subarray and output its length. Or you should print 0 if you cannot find any.

输入

There are multiple test cases.
Each case starts with a line containing three positive integers N,C,K(N,C,K≤1e5).
The second line contains N integer a1,a2,...,aN(1≤ai≤C).
We guarantee that the sum of Ns, the sum of Cs and the sum of Ks in all test cases are all no larger than 5×1e5.
 

输出

For each test case, output one line containing an integer denoting the length of the longest good subarray.

样例输入 复制

7 4 2
2 1 4 1 4 3 2

样例输出 复制

4

来源/分类