[题解] [USACO 2013 Jan]Cow Lineup C++

题目

Description

Cow Lineup [Brian Dean and Daniel Dara, 2012] Farmer John’s N cows
(1 <= N <= 100,000) are lined up in a row. Each cow is identified
by an integer “breed ID” in the range 0…1,000,000,000; the breed
ID of the ith cow in the lineup is B(i). Multiple cows can share the
same breed ID. FJ thinks that his line of cows will look much more
impressive if there is a large contiguous block of cows that all have
the same breed ID. In order to create such a block, FJ chooses up to K
breed IDs and removes from his lineup all the cows having those IDs.
Please help FJ figure out the length of the largest consecutive block
of cows with the same breed ID that he can create by doing this.
有N头牛(1 <= N <= 100,000) 排成一列。每头牛有一个标号,范围在0到1000000000,
第 i 头牛的编号为B(i)。多头牛可以共享一个编号。John想,如果前后相邻的多头牛
能有相同的编号,将会更好。为了使前后相连且编号相同的牛的数量尽可能多,
John将选择 K 个编号,然后移除编号与这K个编号相同的牛。请帮忙选择编号。

Input

第1行:N和K
第2至N+1行:Line i+1 第i头牛的编号 B(i)

Output

连续的编号相同的牛的最大总数。

Sample Input

9 1
2
7
3
7
7
3
7
5
7
有9头牛,要选择1个编号的牛移除。

Sample Output

4
提示:通过移除编号是

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值