2019-04-13 23:58:25 UNSELECTED

```c #include <stdio.h> #include <stdlib.h> int ma

Copy Copied! Full
#include <stdio.h> #include <stdlib.h> int main(void){ int n,k,a,i,j; scanf("%d%d",&n,&k); char s[100001]; int b[100001]={0}; int c[100001]; scanf("%s",s); a = 0; int temp=0; for(i=0;i<n;i){ if(s[i]=='0'){ while(s[i]=='0'){ b[a]--; i++; } a++; temp++; } if(s[i]=='1'){ while(s[i]=='1'){ b[a]++; i++; } a++; } } //次に累積和を考える! c[0]=0; for(i=0;i<a;i++){ c[i+1]=abs(b[i])+c[i]; } for(i=0;i<=n;i++){ printf("c[%d]= %d\n",i,c[i]); } int ans = 0; temp = 0; printf("%d",ans); return 0; }
```c
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int n,k,a,i,j;
	scanf("%d%d",&n,&k);
	char s[100001];
	scanf("%s",s);
	a = s[0] == '0' ? 1 : 0;;
	int temp=0;
    int ans=1;
	for(i=1;i<n;i++){
		if(s[i-1]=='1'&&s[i]=='0'){
            a++;
            if(a>k){
			    if (s[temp] == '1') while (s[temp] == '1') temp++;
                while (s[temp] == '0') temp++;
                if(i<temp)i = temp;
                a--;
            }
		}
		if(ans<i-temp+1)ans=i-temp+1;
	}
	printf("%d",ans);
	return 0;
}
```
RECOMMEND