#P3069. [USACO13JAN] Cow Lineup G

    ID: 2108 远端评测题 2000ms 126MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2013USACO树状数组单调队列队列

[USACO13JAN] Cow Lineup G

Description

Farmer John (FJ) has NN cows (1N1000001 \le N \le 100\,000) standing in a row. Each cow has an integer breed ID in the range 010000000000 \ldots 1\,000\,000\,000; the breed ID of the ii-th cow is B(i)B(i). Multiple cows may share the same breed ID.

FJ may choose up to KK 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 NN and KK.
  • Lines 2 to 1+N1+N: Line i+1i+1 contains B(i)B(i).

Output Format

  • Line 1: The maximum size of a contiguous block of cows with identical breed IDs that FJ can obtain.
9 1 
2 
7 
3 
7 
7 
3 
7 
5 
7 

4 

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