F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Longest Subarray

Time 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
7 4 2 2 1 4 1 4 3 2
 

Sample Output
4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-21 20:47:34, Gzip enabled