Buggy python submission (verdict: Time Limit Exceeded):
n, k=map(int, input().split())
s=list(map(int, list(input())))
renzoku_list=[0]
sum=1
before=s[0]
for i in range(1, n):
    if s[i]==before:
        sum=sum+1
        before=s[i]
    else:
        renzoku_list.append(sum)
        sum=1
        before=s[i]
renzoku_list.append(sum)
renzoku_list.append(0)
result_list=[]
length=len(renzoku_list)

max=0
if s[0]==0 and -(-(length-2)//2)<=k:
    print(n)
elif s[0]==1 and (length-2)//2<=k:
    print(n)
elif s[0]==0:
    for i in range(0, length-(2*k+1)+1, 2):
        result=0
        for j in range(i, i+2*k+1):
            result=result+renzoku_list[j]
        if max<=result:
            max=result
    print(max)
elif s[0]==1:
    for i in range(1, length-(2*k+1)+1, 2):
        result=0
        for j in range(i, i+2*k+1):
            result=result+renzoku_list[j]
        if max<=result:
            max=result
    print(max)


Fixed submission:
n, k=map(int, input().split())
s=list(map(int, list(input())))
if s[0]==0:
    renzoku_list=[0]
else:
    renzoku_list=[]
sum=1
before=s[0]
for i in range(1, n):
    if s[i]==before:
        sum=sum+1
        before=s[i]
    else:
        renzoku_list.append(sum)
        sum=1
        before=s[i]
renzoku_list.append(sum)
if s[n-1]==0:
    renzoku_list.append(0)
ruisekiwa=[0]
for i in range(len(renzoku_list)):
    ruisekiwa.append(renzoku_list[i]+ruisekiwa[i])

length=len(renzoku_list)

max=0

if (length-1)//2<=k:
    print(n)
else:
    for i in range(len(ruisekiwa)-(2*k+1)):
        if i%2==0:#i=0,2,4,...
            sum=ruisekiwa[i+2*k+1]-ruisekiwa[i]
            if sum>=max:
                max=sum
    print(max)

Buggy python submission (verdict: Time Limit Exceeded):
n, k=map(int, input().split())
s=list(map(int, list(input())))
renzoku_list=[0]
sum=1
before=s[0]
for i in range(1, n):
    if s[i]==before:
        sum=sum+1
        before=s[i]
    else:
        renzoku_list.append(sum)
        sum=1
        before=s[i]
renzoku_list.append(sum)
renzoku_list.append(0)
result_list=[]
length=len(renzoku_list)

max=0
if s[0]==0 and -(-(length-2)//2)<=k:
    print(n)
elif s[0]==1 and (length-2)//2<=k:
    print(n)
elif s[0]==0:
    for i in range(length-(2*k+1)+1):
        if i%2==0:
            result=0
            for j in range(i, i+2*k+1):
                result=result+renzoku_list[j]
            if max<=result:
                max=result
    print(max)
elif s[0]==1:
    for i in range(length-(2*k+1)+1):
        if i%2==1:
            result=0
            for j in range(i, i+2*k+1):
                result=result+renzoku_list[j]
            if max<=result:
                max=result
    print(max)


Fixed submission:
n, k=map(int, input().split())
s=list(map(int, list(input())))
if s[0]==0:
    renzoku_list=[0]
else:
    renzoku_list=[]
sum=1
before=s[0]
for i in range(1, n):
    if s[i]==before:
        sum=sum+1
        before=s[i]
    else:
        renzoku_list.append(sum)
        sum=1
        before=s[i]
renzoku_list.append(sum)
if s[n-1]==0:
    renzoku_list.append(0)
ruisekiwa=[0]
for i in range(len(renzoku_list)):
    ruisekiwa.append(renzoku_list[i]+ruisekiwa[i])

length=len(renzoku_list)

max=0

if (length-1)//2<=k:
    print(n)
else:
    for i in range(len(ruisekiwa)-(2*k+1)):
        if i%2==0:#i=0,2,4,...
            sum=ruisekiwa[i+2*k+1]-ruisekiwa[i]
            if sum>=max:
                max=sum
    print(max)