2019-04-14 01:00:09 UNSELECTED

Unknown type code

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]; } int ans = 0; temp = 0; for(i=0;i<n-((2*k)+1);i++){ temp = c[i+(2*k)+1]-c[i]; if(ans<temp)ans = temp; } printf("%d",ans); return 0; }