Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = list(map(int,input()))
tmp = 1
nums = []
cont = 0
for s in S:
    if int(s) == tmp:
        cont += 1
    else:
        nums.append(cont)
        cont = 1
        tmp = 1 - tmp
if cont != 0:
    nums.append(cont)
if len(nums) % 2 == 0:
    nums.append(0)
ans = 0
lst = []
for i in range(0,len(nums),2):
    for j in range(i,min(i+K*2+1,len(nums))):
        ans += nums[j]
    lst.append(ans)
    ans = 0
print(max(lst))

Fixed submission:
N,K = map(int,input().split())
S = list(map(int,input()))
tmp = 1
nums = []
cont = 0
for s in S:
    if int(s) == tmp:
        cont += 1
    else:
        nums.append(cont)
        cont = 1
        tmp = 1 - tmp
if cont != 0:
    nums.append(cont)
if len(nums) % 2 == 0:
    nums.append(0)
cml = [0]
for n in nums:
    cml.append(cml[-1]+n)
ans = []
for i in range(0,len(cml),2):
    ans.append(cml[min(len(cml)-1,i+K*2+1)]-cml[i])
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = list(map(int,input()))
tmp = 1
tbl = []
cont = 0
for s in S:
    if s == tmp:
        cont += 1
    else:
        tbl.append(cont)
        cont = 1
        tmp = abs(tmp-1)
tbl.append(cont)
if len(tbl) % 2 == 0:
    tbl.append(0)
max = 0
for i in range(0,len(tbl),2):
    if sum(tbl[i:i+K*2+1]) > max:
        max = sum(tbl[i:i+K*2+1])
print(max)

Fixed submission:
N,K = map(int,input().split())
S = list(map(int,input()))
tmp = 1
nums = []
cont = 0
for s in S:
    if int(s) == tmp:
        cont += 1
    else:
        nums.append(cont)
        cont = 1
        tmp = 1 - tmp
if cont != 0:
    nums.append(cont)
if len(nums) % 2 == 0:
    nums.append(0)
cml = [0]
for n in nums:
    cml.append(cml[-1]+n)
ans = []
for i in range(0,len(cml),2):
    ans.append(cml[min(len(cml)-1,i+K*2+1)]-cml[i])
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = input()
tmp = 1
tbl = []
cont = 0
for s in S:
    if int(s) == tmp:
        cont += 1
    else:
        tbl.append(cont)
        cont = 1
        tmp = abs(tmp-1)
tbl.append(cont)
if len(tbl) % 2 == 0:
    tbl.append(0)
max = 0
for i in range(0,len(tbl),2):
    if sum(tbl[i:i+K*2+1]) > max:
        max = sum(tbl[i:i+K*2+1])
print(max)

Fixed submission:
N,K = map(int,input().split())
S = list(map(int,input()))
tmp = 1
nums = []
cont = 0
for s in S:
    if int(s) == tmp:
        cont += 1
    else:
        nums.append(cont)
        cont = 1
        tmp = 1 - tmp
if cont != 0:
    nums.append(cont)
if len(nums) % 2 == 0:
    nums.append(0)
cml = [0]
for n in nums:
    cml.append(cml[-1]+n)
ans = []
for i in range(0,len(cml),2):
    ans.append(cml[min(len(cml)-1,i+K*2+1)]-cml[i])
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = input()
tmp = 1
tbl = []
cont = 0
for s in S:
    if int(s) == tmp:
        cont += 1
    else:
        tbl.append(cont)
        cont = 1
        tmp = abs(tmp-1)
tbl.append(cont)
if len(tbl) % 2 == 0:
    tbl.append(0)
max = 0
for i in range(0,len(tbl),2):
    if len(tbl) == 1:
        max = tbl[i]
        break
    if sum(tbl[i:i+K*2+1]) > max:
        max = sum(tbl[i:i+K*2+1])
print(max)

Fixed submission:
N,K = map(int,input().split())
S = list(map(int,input()))
tmp = 1
nums = []
cont = 0
for s in S:
    if int(s) == tmp:
        cont += 1
    else:
        nums.append(cont)
        cont = 1
        tmp = 1 - tmp
if cont != 0:
    nums.append(cont)
if len(nums) % 2 == 0:
    nums.append(0)
cml = [0]
for n in nums:
    cml.append(cml[-1]+n)
ans = []
for i in range(0,len(cml),2):
    ans.append(cml[min(len(cml)-1,i+K*2+1)]-cml[i])
print(max(ans))