P3069 [USACO13JAN] Cow Lineup G

Description

Farmer John (FJ) has $N$ cows ($1 \le N \le 100\,000$) standing in a row. Each cow has an integer breed ID in the range $0 \ldots 1\,000\,000\,000$; the breed ID of the $i$-th cow is $B(i)$. Multiple cows may share the same breed ID. FJ may choose up to $K$ breed IDs and remove from the lineup all cows having those IDs. Determine the maximum possible length of a contiguous block of cows in which all remaining cows have the same breed ID.

Input Format

- Line 1: Two space-separated integers $N$ and $K$. - Lines 2 to $1+N$: Line $i+1$ contains $B(i)$.

Output Format

- Line 1: The maximum size of a contiguous block of cows with identical breed IDs that FJ can obtain.

Explanation/Hint

There are 9 cows in the lineup with breed IDs 2, 7, 3, 7, 7, 3, 7, 5, 7. FJ would like to remove up to 1 breed ID. By removing all cows with breed ID 3, the lineup becomes 2, 7, 7, 7, 7, 5, 7. In this new lineup, there is a contiguous block of 4 cows with the same breed ID (7). Translated by ChatGPT 5