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
*/