- Time: 2016-04-09-23:59:40 Saturday
- Title Number: [2016-04-09][codeforces][660][c][hard Process]
- Title: Given a sequence of 0 1, the maximum number of K 0 is changed to 1, the longest 1 substring is how long,
- Analysis:
- Two-point answer
- Check (): Enumerates substrings of mid and determines whether the number of 0 inside is less than or equal to 1,
#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;
}
From for notes (Wiz)
[2016-04-09] [Codeforces] [660] C [Hard Process]