Buggy python submission (verdict: Runtime Error):
l, accum = len(s), []
i = 0
while i < l:
    ch = s[i]
    count = 0
    while i < l and s[i] == ch:
        count += 1
        i += 1
    accum.append(count)

l = len(accum)
for i in range(1, l): accum[i] += accum[i-1]

mx = accum[min(2*k - (1-int(s[0])), l-1)]
i = 1
while l > 1:
    idx = min(2*k - (1-int(s[0])) + 2*i, l-1)
    mx = max(accum[idx] - accum[2*(i-1)+int(s[0])], mx)
    if idx >= l-1: break
    i += 1                                                                                                     
print(mx)

Fixed submission:
N, k = map(int, input().split())                                                                               
s = input()

l, accum = len(s), []
i = 0
while i < l:
    ch = s[i]
    count = 0
    while i < l and s[i] == ch:
        count += 1
        i += 1
    accum.append(count)

l = len(accum)
for i in range(1, l): accum[i] += accum[i-1]

mx = accum[min(2*k - (1-int(s[0])), l-1)]
i = 1
while l > 1:
    idx = min(2*k - (1-int(s[0])) + 2*i, l-1)
    mx = max(accum[idx] - accum[2*(i-1)+int(s[0])], mx)
    if idx >= l-1: break
    i += 1
print(mx)

Buggy python submission (verdict: Runtime Error):
N, k = map(int, input().split())
s = input()

def count_consecutive(s):
    return max(list(map(lambda x: len(x), s.split('0'))))

def dfs(s, k, st):
    global mx
    if mx == N: return mx
    if k:
        for j in range(st, len(pos)):                                                                          
            i, count = pos[j]
            mx = max(dfs(s[:i] + '1'*count + s[i+count:], k-1, j+1), mx) 
    return max(count_consecutive(s), mx) 

l, mx, pos = len(s), 0, []
i = 0 
while i < l:
    if s[i] == '0':
        count = 0 
        while i+count < l and s[i+count] == '0':
            count += 1
        pos.append([i, count])
        i += count
    else:
        i += 1
print(dfs(s, k, 0))

Fixed submission:
N, k = map(int, input().split())                                                                               
s = input()

l, accum = len(s), []
i = 0
while i < l:
    ch = s[i]
    count = 0
    while i < l and s[i] == ch:
        count += 1
        i += 1
    accum.append(count)

l = len(accum)
for i in range(1, l): accum[i] += accum[i-1]

mx = accum[min(2*k - (1-int(s[0])), l-1)]
i = 1
while l > 1:
    idx = min(2*k - (1-int(s[0])) + 2*i, l-1)
    mx = max(accum[idx] - accum[2*(i-1)+int(s[0])], mx)
    if idx >= l-1: break
    i += 1
print(mx)

Buggy python submission (verdict: Runtime Error):
N, k = map(int, input().split())
s = input()

l = len(s)
mx = 0 

def count_consecutive(s):
    return max(list(map(lambda x: len(x), s.split('0'))))

def dfs(s, k, st):
    global mx
    if k == 0: return count_consecutive(s)
    for i in range(st, l): 
        if s[i] == '0':
            count = 0 
            while i+count < l and s[i+count] == '0':
                count += 1
            mx = max(dfs(s[:i] + '1'*count + s[i+count:], k-1, i+count), mx) 
    return max(count_consecutive(s), mx)                                                                       

print(dfs(s, k, 0)) 

Fixed submission:
N, k = map(int, input().split())                                                                               
s = input()

l, accum = len(s), []
i = 0
while i < l:
    ch = s[i]
    count = 0
    while i < l and s[i] == ch:
        count += 1
        i += 1
    accum.append(count)

l = len(accum)
for i in range(1, l): accum[i] += accum[i-1]

mx = accum[min(2*k - (1-int(s[0])), l-1)]
i = 1
while l > 1:
    idx = min(2*k - (1-int(s[0])) + 2*i, l-1)
    mx = max(accum[idx] - accum[2*(i-1)+int(s[0])], mx)
    if idx >= l-1: break
    i += 1
print(mx)