#P6602. Longest Subarray
Longest Subarray
Problem Description
You are given two integers $C, K$ and an array of $N$ integers $a_1, a_2, ..., a_N$. It is guaranteed that the value of $a_i$ is between $1$ to $C$.
We define that a continuous subsequence $a_l, a_{l + 1}, ..., a_r(l\leq r)$ of array a is a good subarray if and only if the following condition is met:
\begin{equation*}
\forall x \in [1, C], \; \sum\limits_{i = l}^r[a_i = x] = 0 \; or \; \sum\limits_{i = l}^r[a_i = x] \geq K
\end{equation*}
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.
Input
There are multiple test cases.
Each case starts with a line containing three positive integers $N,C,K(N,C,K \leq 10^5)$.
The second line contains $N$ integer $a_1, a_2, ..., a_N(1 \leq a_i \leq C)$.
We guarantee that the sum of $N$s, the sum of $C$s and the sum of $K$s in all test cases are all no larger than $5 \times 10^5$.
Output
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