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的更多相关文章
随机推荐
- webpack入门教程--2
这次是创建第二个JS文件. 我们还是在app文件夹中创建一个叫做book2.js的JS文件,并在其中输入以下代码: module.exports = "It works from book2 ...
- CSS---伪类与伪元素的区别
在CSS中对于伪类和伪元素并没有做出很明显的区别定义,两者的语法是一样的,都是以 : 开头,这样导致我们将一些伪元素误认为伪类,如 :before :after 而在CSS3中给出了明显的定义. ☞ ...
- Vsphere 回收未消使用的磁盘空间
下载sdelete.exe 执行 sdelete.exe -z E: ,然后又恢复为原可用空间 关机 SHH进入物理主机,找到对应的虚机文件 执行vmkfstools -K test-Win200 ...
- 【学习笔记】【Javaweb】二、Session对象过期时间三种设置方法、Session失效监听器
一.前言 本文:https://www.cnblogs.com/Twobox/p/10361712.html 参考:https://www.cnblogs.com/diewufeixian/p/422 ...
- kmalloc分配物理内存与高端内存映射--Linux内存管理(十八)
1 前景回顾 1.1 内核映射区 尽管vmalloc函数族可用于从高端内存域向内核映射页帧(这些在内核空间中通常是无法直接看到的), 但这并不是这些函数的实际用途. 重要的是强调以下事实 : 内核提供 ...
- spring boot 扫描不到自定义Controller
使用springboot启动类配置扫描的两种注解配置方式: 1.@Controller @EnableAutoConfiguration @ComponentScan 2.@SpringBoo ...
- LeetCode算法题-Valid Palindrome II(Java实现)
这是悦乐书的第287次更新,第304篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第155题(顺位题号是680).给定非空字符串s,最多可以删除一个字符. 判断它是否是回 ...
- 用 PLSQL 创建新用户及导入 dmp
一.创建表空间 在导入 dmp 文件之前,你要在数据库里面给它分配一片存储它的地方(表空间). 如果我们知道需要导入的数据库的表空间直接创建就可以,如果不不知道,也没有关系,我们可以用 txt 打开 ...
- SAP CRM Installed Bases(IBase)简介
SAP CRM使用Installed Base(以下简称IBase)来组织服务相关对象并进行管理.因为我在最近的工作中经常接触这个概念,所以学习了一点相关文档.下面是文档的翻译. 本文链接:https ...
- 如何给python程序加密
在实际的工作中,有时候我们需要部署自己的Python应用,但这时候我们并不希望别人能够看到自己的Python源程序.因此,我们需要为自己的源代码进行加密,Python已经为我们提供了这样一套工作机制. ...