测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A10271. Hard Process

编程题 普及/提高-

题目描述

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)$ .

输入格式

The first line contains two integers $n$ and $k$ ( $1<=n<=3·10^{5},0<=k<=n$ ) — the number of elements in $a$ and the parameter $k$ .

The second line contains $n$ integers $a_{i}$ ( $0<=a_{i}<=1$ ) — the elements of $a$ .

输出格式

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 $a_{j}$ — the elements of the array $a$ after the changes.

If there are multiple answers, you can print any one of them.

输入输出样例

输入 #1
7 1
1 0 0 1 1 0 1
输出 #1
4
1 0 0 1 1 1 1
输入 #2
10 2
1 0 0 1 0 1 0 1 0 1
输出 #2
5
1 0 0 1 1 1 1 1 0 1
上一题 去做题 下一题