#P3069. [USACO13JAN] Cow Lineup G
[USACO13JAN] Cow Lineup G
Description
Farmer John (FJ) has cows () standing in a row. Each cow has an integer breed ID in the range ; the breed ID of the -th cow is . Multiple cows may share the same breed ID.
FJ may choose up to 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 and .
- Lines 2 to : Line contains .
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
京公网安备 11011102002149号