CodeForces - 660C
Description You are given an array a with n elements. Each element of a is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a). Input The first line contains two integers n and k (1 ≤ n ≤ 3·105, 0 ≤ k ≤ n) — the number of elements in a and the parameter k. The second line contains n integers ai (0 ≤ ai ≤ 1) — the elements of a. Output On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones. On the second line print n integers aj — the elements of the array a after the changes. If there are multiple answers, you can print any one of them. Sample Input
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
Source
//题意:输入n,k,接着下面一行输入n个数(0或1)
表示给你一个长度为n的序列,让你改变其中的k个0,使得这个序列中连续的1的长度达到最长。输出最长长度并输出改变后的序列。
//思路:
二分法枚举1的最长长度,逐个判断,直到找到最长的连续的1的序列,具体看代码。
|
CodeForces - 660C Hard Process (二分)好题
原创mb643f91219020e 博主文章分类:codeforces ©著作权
©著作权归作者所有:来自51CTO博客作者mb643f91219020e的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章