Hard Process

CodeForces - 660C

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.

Examples

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 sol:只能把0变成1,而且要让连续的一段尽可能的大,于是可以枚举右端点二分左端点,判断那一段0的个数与K的关系
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,a[N],S[N];
int Ans[N];
inline int TwoFind(int l,int r)
{
int Pos=r,ans=r+;;
while(l<=r)
{
int mid=(l+r)>>;
if(S[Pos]-S[mid-]<=m)
{
ans=mid; r=mid-;
}
else l=mid+;
}
return ans;
}
int main()
{
int i,Pos=;
R(n); R(m);
for(i=;i<=n;i++)
{
R(a[i]); S[i]+=S[i-]+(a[i]==);
int oo=TwoFind(,i);
Ans[i]=i-oo+;
if(Ans[i]>Ans[Pos]) Pos=i;
}
Wl(Ans[Pos]);
for(i=Pos;i>=&&m;i--) if(a[i]==) a[i]=,m--;
for(i=;i<=n;i++) W(a[i]);
return ;
}
/*
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
*/
 

codeforces660C的更多相关文章

随机推荐

  1. vue点击按钮给商品按照价格进行倒叙

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. i的二次幂求和

    \(i^2\)求和 老祖宗告诉我们\(\sum_{i=1}^n i^2 = \frac{n(n+1)(2n+1)}{6}\) 但是这玩意儿是怎么出来的呢?感觉网上用立方差证明的思路太low了,今天偶然 ...

  3. 39.Odoo产品分析 (四) – 工具板块(8) – 生产力(1)

    查看Odoo产品分析系列--目录 生产力相当于一个即时贴或便签.用便签或待办事项处理个人的任务.  安装生产力模块,得到"便签"主菜单:  创建一个便签,该表单对应note.not ...

  4. Easyui 实现点击不同树节点打开不同tab页展示不同datagrid表数据设计

    实现点击不同树节点打开不同tab页展示不同datagrid表数据设计 by:授客 QQ:1033553122 测试环境 jquery-easyui-1.5.3 需求描述 如上图, 1.点击左侧树,叶子 ...

  5. TCP/IP、UDP、HTTP、SOCKET详解

    文章大纲 网络OSI七层及各层作用 TCP与UDP基本介绍 TCP连接过程详解 SOCKET原理与连接详解     一.网络OSI七层及各层作用   应用层:文件传输,电子邮件,文件服务,虚拟终端 T ...

  6. GIT的使用(Gitlab上传本地仓库代码,Webstorm修改更新)

    准备:GIT的安装,Gitlab账户登陆,webstorm的安装 1.首先,你得先会在Gitlab中创建一个团体,在团体中创建一个项目,先建组,再建项目,网上哪里都有教程,随便找了个网址: https ...

  7. PYTHON常用数据类型(列表,元组,字典)

    一.数字 1.整形:就是整数. 2.浮点型:就是小数. 3.布尔型:True或者是False,python里严格区分格式,空格缩进或者是大小写. 4.运算符有+ – * / ()%(求模运算取余数)* ...

  8. vmware station-ubuntu18.04 共享剪贴板

    辞职在家休息,买了台新电脑,装个虚拟机,安装visual studio, android studio, qt, everything, noptepad++,hbuilder,ditto,xx-ne ...

  9. 如何在Spring Data JPA中引入Querydsl

    一.环境说明 基础框架采用Spring Boot.Spring Data JPA.Hibernate.在动态查询中,有一种方式是采用Querydsl的方式. 二.具体配置 1.在pom.xml中,引入 ...

  10. Jenkins插件之显示构建时间

    1.进入jenkin插件管理器中,安装  Timestamper 插件 2.安装完成后,进入到构建任务里面,在 构建环境 中勾选  Add timestamps to the Console Outp ...