Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = list(input())
s = list((map(int, s)))
tipS = []
cnt = 1
ans = 0

for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        tipS.append([s[i], cnt])
        cnt = 1
tipS.append([s[-1], cnt])

for i in range(len(tipS)):
    tmp = tipS[i][1]
    if tipS[i][0] == 0:
        cnt_tmp = 1
    else:
        cnt_tmp = 0

    for j in range(i + 1,len(tipS)):

        if tipS[j][0] == 1:
            tmp += tipS[j][1]

        else:
            if cnt_tmp < k:
                cnt_tmp += 1
                tmp += tipS[j][1]
            else:
                break
    ans = max(ans, tmp)

print(ans)


Fixed submission:
n, k = map(int, input().split())
s = list(input())
s = list((map(int, s)))
tipS = []
cnt = 1
ans = 0
zeroInd = []
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        tipS.append([s[i], cnt])
        cnt = 1
tipS.append([s[-1], cnt])
total_sum = [0] * len(tipS)
total_sum[0] += tipS[0][1]
for i in range(len(tipS)):
    if tipS[i][0] == 0:
        zeroInd.append(i)
    if i != 0:
        total_sum[i] += tipS[i][1] + total_sum[i-1]
if len(zeroInd) != 0:
    start = zeroInd[0]
tmp_cnt = 0
tmp = 0
tmp2 = 0
before = 0
#print(total_sum)
for i in range(len(tipS)):

    if tipS[i][0] == 0:
        tmp_cnt += 1


        if tmp_cnt > k:
            ans = max(tmp, ans)
            #print("ans: {}".format(ans))
            tmp -= (total_sum[start] - before)
            before = total_sum[start]
            #print("minus{}".format(tmp))
            tmp += tipS[i][1]
            tmp_cnt -= 1
            tmp2 += 1
            start = zeroInd[tmp2]

        else:
            tmp += tipS[i][1]


    else:
        tmp += tipS[i][1]
    #print("tmp_cnt: {}".format(tmp_cnt))
    #print("tmp: {}".format(tmp))

ans = max(ans, tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = list(input())
s = list((map(int, s)))
tipS = []
cnt = 1
ans = 0

for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        tipS.append([s[i], cnt])
        cnt = 1
tipS.append([s[-1], cnt])

for i in range(len(tipS)):
    tmp = tipS[i][1]
    if tipS[i][0] == 0:
        cnt_tmp = 1
    else:
        cnt_tmp = 0

    for j in range(i + 1,len(tipS)):

        if tipS[j][0] == 1:
            tmp += tipS[j][1]

        else:
            if cnt_tmp < k:
                cnt_tmp += 1
                tmp += tipS[j][1]
            else:
                break
    ans = max(ans, tmp)

print(ans)


Fixed submission:
n, k = map(int, input().split())
s = list(input())
s = list((map(int, s)))
tipS = []
cnt = 1
ans = 0
zeroInd = []
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        tipS.append([s[i], cnt])
        cnt = 1
tipS.append([s[-1], cnt])
total_sum = [0] * len(tipS)
total_sum[0] += tipS[0][1]
for i in range(len(tipS)):
    if tipS[i][0] == 0:
        zeroInd.append(i)
    if i != 0:
        total_sum[i] += tipS[i][1] + total_sum[i-1]
if len(zeroInd) != 0:
    start = zeroInd[0]
tmp_cnt = 0
tmp = 0
tmp2 = 0
before = 0
#print(total_sum)
for i in range(len(tipS)):

    if tipS[i][0] == 0:
        tmp_cnt += 1


        if tmp_cnt > k:
            ans = max(tmp, ans)
            #print("ans: {}".format(ans))
            tmp -= (total_sum[start] - before)
            before = total_sum[start]
            #print("minus{}".format(tmp))
            tmp += tipS[i][1]
            tmp_cnt -= 1
            tmp2 += 1
            start = zeroInd[tmp2]

        else:
            tmp += tipS[i][1]


    else:
        tmp += tipS[i][1]
    #print("tmp_cnt: {}".format(tmp_cnt))
    #print("tmp: {}".format(tmp))

ans = max(ans, tmp)

print(ans)