codeforces660C
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).
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
7 1
1 0 0 1 1 0 1
4
1 0 0 1 1 1 1
10 2
1 0 0 1 0 1 0 1 0 1
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的更多相关文章
随机推荐
- 纯CSS实现点击事件展现隐藏div菜单列表/元素切换
在写移动端导航的时候经常用到点击按钮出现/隐藏导航条的情况,最常见的方法当然还是前端框架直接调用,省心省力,不易出错:当然还有使用纯JS实现的小代码段.我这里整理了纯CSS实现方式,给需要的人和给自己 ...
- git操作+一个本地项目推到github上+注意
git init 创建新文件夹,打开,然后执行以创建新的 git 仓库. git config --global user.name "xxx" git config --glob ...
- MockJS和Easy Mock使用
之前做mock数据一直用的json-server,今天同事给我推荐了很好用的工具:Easy Mock,我看完之后是下图的状态 很得劲啊,感觉人生已经达到了高潮 既能伪造接口,又能根据既定的规则生成对应 ...
- weblogic Patch
How to Apply WLS Patch on Weblogic Integrated with OEM Getting "Main Thread" Java.lang.Out ...
- Neutron server的运行原理(未完待续)
1.Neutron server首先是一个web server, 对于http和https协议的报文进行响应. 2.Neutron server进程里面包含了一个WSGI 应用程序,以及不同模块的pl ...
- arcgis for js学习之Draw类
arcgis for js学习之Draw类 <!DOCTYPE html> <html> <head> <meta http-equiv="Cont ...
- 使用OCLint和Sonar对iOS代码分析和质量管理
OCLint 是一个强大的静态代码分析工具,可以用来提高代码质量,查找潜在的bug,主要针对c,c++和Objective-c的静态分析. Sonar 是一个用于代码质量管理的开放平台.通过插件机制, ...
- Android为TV端助力 MediaPlayer 错误代码(error code)总结 转载
public static final int MEDIA_ERROR_IO Added in API level 17 File or network related operation error ...
- [外包]!采用asp.net core 快速构建小型创业公司后台管理系统(六.结语)
到这里就结束了,真的结束了,源码会在文末分享! 另外录了两个视频,对这个系统进行了演示! 做有意义的事情,原此生无悔! 视频地址:使用asp.net core 快速构建权限管理模块1 使用asp.ne ...
- CAP理论和Base理论
CAP理论 Consistency(一致性), 数据一致更新,所有数据变动都是同步的 Availability(可用性), 好的响应性能 Partition tolerance(分区容错性) 可靠性, ...