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·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.
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.
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
这个题和上次一个aabbaa翻转m次求最长全a或者全b序列特别相似,只不过这是就最长全1序列长度,并且输出。所以同样用前缀和 + 二分,求得最大值时顺便保存位置,输出的时候对应输出就行了。1600+过题数,挺水的
/*************************************************************************
> File Name: 660C.cpp
> Author: Triose
> Mail: Triose@163.com
> Created Time: 2016年06月05日 星期日 12时46分49秒
************************************************************************/
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for(int (i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
int n, m;
#define N 300010
int a[N];
int s, e;
int max_len;
void brain_serach(int th) {
int low = m + th - 1;
int high = n;
while(low <= high) {
int mid = (low + high) >> 1;
if(a[mid] - a[th - 1] <= m) {
if(mid - th + 1 > max_len) {
//printf("%d %d %d\n\n", th, mid, max_len);
max_len = mid - th + 1;
s = th; e = mid;
}
low = mid + 1;
}
else {
high = mid - 1;
}
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("Out.txt", "w", stdout);
#endif
while(~sfd(n,m)) {
mem(a,0);
max_len = 0;
rep(i, n) {
sf(a[i + 1]);
a[i + 1] = (1 - a[i + 1]) + a[i];
}
for(int i = 1; i <= n; i++) brain_serach(i);
pf(max_len);
for(int i = 1; i <= n; i++) {
if(i <= e && i >= s) {
printf("1%c", i == n ? '\n' : ' ');
continue;
}
printf("%d%c", 1 - (a[i] - a[i - 1]), i == n ? '\n' : ' ');
}
}
return 0;
}