uestc 1904

#include<stdio.h>
#define N  1010
int min[N];
int main() {
int t,n,p,ti,first,end,num,i,j,max,k;
char s[N];
scanf("%d",&t);
while(t--) {
scanf("%d%d",&n,&p);
first=1;
ti=0;
scanf("%s",s);
i=0;num=0;
while(s[i]!='1'&&i<n)
i++;
if(i==n) {
printf("0\n");
continue;
}
i++;
min[first]=0;
end=1;max=0;k=0;
for(j=i;j<n;j++) {
ti++;
if(s[j]=='1')
min[++end]=ti;
else 
if(s[j]=='2'){
if(first<=end) {
while(min[first]+p<ti&&first<=end)
first++;
if(first<=end) {
num+=2;
first++;
}
}
}
while(min[first]+p<ti+1&&first<=end)
first++;
if(num+end-first+1>=max)
max=num+end-first+1;
}
ti++;
while(first<=end) {
if(min[first]+p>=ti)
k++;
first++;
}
if(num+k>max)
max=num+k;
printf("%d\n",max);
}
return 0;
}









posted @ 2013-12-18 22:06  HYDhyd  阅读(121)  评论(0编辑  收藏  举报