|
||||||||||
Longest SubarrayTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 3164 Accepted Submission(s): 952 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. Sample Input
Sample Output
Source | ||||||||||
|