Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = list(map(int,input()))
blobs = []
if S[0] == 0:
    blobs.append(0)
cnt = 0
past_i = 0
for i in range(len(S)):
    if i == 0:
        past_i = S[i]
    if past_i == S[i]:
        cnt += 1
        past_i = S[i]
        
    else:
        blobs.append(cnt)
        cnt = 1
        past_i = S[i]
    if i == len(S)-1:
        blobs.append(cnt)

if S[-1] == 0:
    blobs.append(0)
sums = []
len_blobs = len(blobs)

# 
for i in range(len(blobs)//2-min(K,len_blobs//2)+1):
    temp_sum = sum(blobs[2*i:2*(i+K)+1])
    sums.append(temp_sum)
    if temp_sum == N:
        break
print(max(sums))

Fixed submission:
N,K = map(int,input().split())
S = input()
one = [0]
zero = [0]
if S[0] == '0':
    one.append(0)
cnt = 1
for i in range(1,len(S)):
    if S[i] != S[i-1]:
        if S[i-1] == '1':
            one.append(cnt+one[-1])                
        else:
            zero.append(cnt+zero[-1])                
        cnt = 1
    else:
        cnt += 1
else:
    if S[-1] == '1':
        one.append(cnt+one[-1])                
    else:
        zero.append(cnt+zero[-1])                
        one.append(one[-1])                
window_size = min(len(zero)-1,K)
MAX = 0
for i in range(len(zero)-window_size):
    if MAX < (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i]):
        MAX = (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i])

print(MAX)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = list(map(int,input()))
blobs = []
if S[0] == 0:
    blobs.append(0)
cnt = 0
past_i = 0
for i in range(len(S)):
    if i == 0:
        past_i = S[i]
    if past_i == S[i]:
        cnt += 1
        past_i = S[i]
        
    else:
        blobs.append(cnt)
        cnt = 1
        past_i = S[i]
    if i == len(S)-1:
        blobs.append(cnt)

if S[-1] == 0:
    blobs.append(0)
sums = []
for i in range(len(blobs)//2-min(K,len(blobs)//2)+1):
    temp_sum = sum(blobs[2*i:min(2*(i+K)+1,len(blobs))])
    sums.append(temp_sum)
    if temp_sum == N:
        break
print(max(sums))

Fixed submission:
N,K = map(int,input().split())
S = input()
one = [0]
zero = [0]
if S[0] == '0':
    one.append(0)
cnt = 1
for i in range(1,len(S)):
    if S[i] != S[i-1]:
        if S[i-1] == '1':
            one.append(cnt+one[-1])                
        else:
            zero.append(cnt+zero[-1])                
        cnt = 1
    else:
        cnt += 1
else:
    if S[-1] == '1':
        one.append(cnt+one[-1])                
    else:
        zero.append(cnt+zero[-1])                
        one.append(one[-1])                
window_size = min(len(zero)-1,K)
MAX = 0
for i in range(len(zero)-window_size):
    if MAX < (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i]):
        MAX = (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i])

print(MAX)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = list(map(int,input()))
blobs = []
if S[0] == 0:
    blobs.append(0)
cnt = 0
past_i = 0
for i in range(len(S)):
    if i == 0:
        past_i = S[i]
    if past_i == S[i]:
        cnt += 1
        past_i = S[i]
        
    else:
        blobs.append(cnt)
        cnt = 1
        past_i = S[i]
    if i == len(S)-1:
        blobs.append(cnt)

if S[-1] == 0:
    blobs.append(0)
print(blobs)
sums = []
for i in range(len(blobs)//2-K+1):
    temp_sum = sum(blobs[2*i:min(2*(i+K)+1,len(blobs))])
    sums.append(temp_sum)
    if temp_sum == N:
        break
print(max(sums))

Fixed submission:
N,K = map(int,input().split())
S = input()
one = [0]
zero = [0]
if S[0] == '0':
    one.append(0)
cnt = 1
for i in range(1,len(S)):
    if S[i] != S[i-1]:
        if S[i-1] == '1':
            one.append(cnt+one[-1])                
        else:
            zero.append(cnt+zero[-1])                
        cnt = 1
    else:
        cnt += 1
else:
    if S[-1] == '1':
        one.append(cnt+one[-1])                
    else:
        zero.append(cnt+zero[-1])                
        one.append(one[-1])                
window_size = min(len(zero)-1,K)
MAX = 0
for i in range(len(zero)-window_size):
    if MAX < (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i]):
        MAX = (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i])

print(MAX)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = list(map(int,input()))
blobs = []
if S[0] == 0:
    blobs.append(0)
cnt = 0
past_i = 0
for i in range(len(S)):
    if i == 0:
        past_i = S[i]
    if past_i == S[i]:
        cnt += 1
    else:
        blobs.append(cnt)
        cnt = 1
        past_i = S[i]
if S[-1] == 0:
    blobs.append(0)
sums = []
for i in range(len(blobs)//2):
    sums.append(sum(blobs[2*i:2*(i+K+1)]))
print(max(sums))
    

Fixed submission:
N,K = map(int,input().split())
S = input()
one = [0]
zero = [0]
if S[0] == '0':
    one.append(0)
cnt = 1
for i in range(1,len(S)):
    if S[i] != S[i-1]:
        if S[i-1] == '1':
            one.append(cnt+one[-1])                
        else:
            zero.append(cnt+zero[-1])                
        cnt = 1
    else:
        cnt += 1
else:
    if S[-1] == '1':
        one.append(cnt+one[-1])                
    else:
        zero.append(cnt+zero[-1])                
        one.append(one[-1])                
window_size = min(len(zero)-1,K)
MAX = 0
for i in range(len(zero)-window_size):
    if MAX < (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i]):
        MAX = (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i])

print(MAX)