#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=100010;
char str[maxn];
int num[maxn];
int main()
{
int n,k,i,j;
scanf("%d%d",&n,&k);
scanf("%s",str+1);
int ans=inf,left=1,cnt=1,temp=0;
for(i=1;i<=n;++i){
if(str[i]=='0'){
temp++;num[cnt++]=i;
if(temp==k+1){
int l=left,r=cnt-1,x=inf;temp-=1;int right=r;
while(l<=r){
int mid=(l+r)>>1;
x=min(x,max(num[mid]-num[left],num[right]-num[mid]));
if(num[mid]-num[left]>num[right]-num[mid]){
r=mid-1;
}
else {
l=mid+1;
}
}
left+=1;
ans=min(ans,x);
}
}
}
printf("%d\n",ans);
return 0;
}
cf645C. Enduring Exodus
最新推荐文章于 2020-05-19 19:42:52 发布