Language: C

#include <stdio.h>

int sum(int *hairetsu,int n){
	int sum_add=0;
	for(int num=0;num<n;num++){
		sum_add += hairetsu[num];
	}
	return sum_add;
}

int main(){
	char s[100001];
	int n;
	int k;
	int a = scanf("%d", &n);
	a = scanf("%d", &k);
	a = scanf("%s", s);
	
	int cnt = 0;
	int init = s[0]=='0'?0:1;
	int h[100001] = {};
	int h_cnt = 0;
	
	for(int i=1;i<n;i++){
		if(s[i-1]!=s[i]){
			h[h_cnt++]+=1;
		}
		else{
			h[h_cnt]+=1;
		}
	}
	//h_cnt is finally length of h_cnt
	
	int zero_num = 0;
	int max = 0;
	if(init){ //start with 1
		zero_num = h_cnt/2;
		if(zero_num<=k){
			printf('%d', n);
		}
		else{
			int sum_0 = sum(h,k*2+1);
			int max = sum_0;
			for(int j=0;j<=zero_num-k+1;j++){ //j is 0's location
				sum_0 = sum_0 - h[j*2] - h[j*2+1] + h[(j+k)*2+1] + h[(j+k+1)*2];
				if(max<=sum_0){
					max = sum_0;
				}
			}
			printf('%d', max)
		}
	}
	else{ //start with 0
		zero_num = h_cnt/2 +1;
		if(zero_num<=k){
			printf('%d', n);
		}
		else{
			int sum_0 = sum(h,k*2);
			int max = sum_0;
			for(int j=0;j<=zero_num-k+1;j++){ //j is 0's location
				sum_0 = sum_0 - h[j*2] - h[j*2+1] + h[(j+k)*2] + h[(j+k)*2+1];
				if(max<=sum_0){
					max = sum_0;
				}
			}
			printf('%d', max)
		}
	}
	return 0;
}

Compiler output:
main.c: In function 'main':
main.c:39:32: warning: multi-character character constant [-Wmultichar]
   39 |                         printf('%d', n);
      |                                ^~~~
main.c:39:32: error: passing argument 1 of 'printf' makes pointer from integer without a cast [-Wint-conversion]
   39 |                         printf('%d', n);
      |                                ^~~~
      |                                |
      |                                int
In file included from main.c:1:
/usr/include/stdio.h:363:43: note: expected 'const char * restrict' but argument is of type 'int'
  363 | extern int printf (const char *__restrict __format, ...);
      |                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
main.c:50:32: warning: multi-character character constant [-Wmultichar]
   50 |                         printf('%d', max)
      |                                ^~~~
main.c:50:32: error: passing argument 1 of 'printf' makes pointer from integer without a cast [-Wint-conversion]
   50 |                         printf('%d', max)
      |                                ^~~~
      |                                |
      |                                int
/usr/include/stdio.h:363:43: note: expected 'const char * restrict' but argument is of type 'int'
  363 | extern int printf (const char *__restrict __format, ...);
      |                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
main.c:50:42: error: expected ';' before '}' token
   50 |                         printf('%d', max)
      |                                          ^
      |                                          ;
   51 |                 }
      |                 ~                         
main.c:56:32: warning: multi-character character constant [-Wmultichar]
   56 |                         printf('%d', n);
      |                                ^~~~
main.c:56:32: error: passing argument 1 of 'printf' makes pointer from integer without a cast [-Wint-conversion]
   56 |                         printf('%d', n);
      |                                ^~~~
      |                                |
      |                                int
/usr/include/stdio.h:363:43: note: expected 'const char * restrict' but argument is of type 'int'
  363 | extern int printf (const char *__restrict __format, ...);
      |                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
main.c:67:32: warning: multi-character character constant [-Wmultichar]
   67 |                         printf('%d', max)
      |                                ^~~~
main.c:67:32: error: passing argument 1 of 'printf' makes pointer from integer without a cast [-Wint-conversion]
   67 |                         printf('%d', max)
      |                                ^~~~
      |                                |
      |                                int
/usr/include/stdio.h:363:43: note: expected 'const char * restrict' but argument is of type 'int'
  363 | extern int printf (const char *__restrict __format, ...);
      |                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
main.c:67:42: error: expected ';' before '}' token
   67 |                         printf('%d', max)
      |                                          ^
      |                                          ;
   68 |                 }
      |                 ~