标签:
#include<cstdio>
using namespace std;
const int maxn = 3*1E5 + 10;
int a[maxn],b[maxn],n,k;
int check(int x){
for(int i = x ; i <= n ; ++i){
if(b[i] - b[i - x] + k >= x) return 1;
}
return 0;
}
void print(int x){
int flg = 0;
for(int i = x ; i <= n ; ++i){
if(b[i] - b[i - x] + k >= x){
for(int j = i - x + 1;j <= i ; ++j){
a[j] = 1;flg = 1;
}
}
if(flg) break;
}
for(int i = 1;i <= n ; ++i) printf("%d ",a[i]);
}
int main(){
scanf("%d%d",&n,&k);
for(int i = 1 ; i <= n ; ++i){
scanf("%d",a+i);
b[i] = b[i - 1] + a[i];
}
int l = 0,r = n + 1,mid,res;
while(r >= l){
mid = (l + r)>>1;
if(check(mid)){
l = mid + 1;
res = mid;
}
else r = mid - 1;
}
printf("%d\n",res);
print(res);
return 0;
}
[2016-04-09][codeforces][660][C][Hard Process]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/b59193307440e81cdda1b49e7d7a3fb2.html