Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
s = list(map(int,input()))
s.append(2)
start = s[0]
choku = [0]
saka = [0]
number = 1
for i in range(N):
    if s[i] == s[i+1]:
        number += 1
    else:
        if s[i] == 0:
            choku.append(number)
            number = 1
        else:
            saka.append(number)
            number = 1
choku.append(0)
saka.append(0)
while(1):
    max_align = 0
    m = len(choku)
    n = len(saka)
    if m <= K:
        print(N)
        break
    if start == 0: #最初が直立の場合
        for i in range(m-K+1):
            if max_align <= sum(choku[i:i+K]) + sum(saka[i-1:i+K]):
                max_align = sum(choku[i:i+K]) + sum(saka[i-1:i+K])
    else:
        for i in range(m-K+1):
            if max_align <= sum(choku[i:i+K]) + sum(saka[i:i+K+1]):
                max_align = sum(choku[i:i+K]) + sum(saka[i:i+K+1])
    print(max_align)
    break

Fixed submission:
N,K = map(int,input().split())
s = list(map(int,input()))
s.append(2)
start = s[0]
number = 1
choku = []
saka = [0]
for i in range(N):
    if s[i] == s[i+1]:
        number += 1
    else:
        if s[i] == 0:
            choku.append(number)
            number = 1
        else:
            saka.append(number)
            number = 1
choku.append(0)
saka.append(0)
while(1):
    max_align = 0
    m = len(choku)
    n = len(saka)
    if m <= K:
        print(N)
        break
    if start == 0: #最初が直立の場合
        aligns = [sum(choku[0:K]) + sum(saka[0:K+1])]
        for i in range(m-K-1):
            aligns.append(aligns[i] -choku[i]-saka[i] + choku[i+K] + saka[i+K+1])
        print(max(aligns))
    else:
        aligns = [sum(choku[0:K]) + sum(saka[1:K+2])]
        for i in range(m-K-1):
            aligns.append(aligns[i] -choku[i]-saka[i+1] + choku[i+K] + saka[i+K+2])
        print(max(aligns))
    break

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
s = list(map(int,input()))
s.append(2)
start = s[0]
choku = [0]
saka = [0]
number = 1
for i in range(N):
    if s[i] == s[i+1]:
        number += 1
    else:
        if s[i] == 0:
            choku.append(number)
            number = 1
        else:
            saka.append(number)
            number = 1
choku.append(0)
saka.append(0)
while(1):
    max_align = 0
    m = len(choku)
    n = len(saka)
    if m <= K:
        print(N)
        break
    if start == 0: #最初が直立の場合
        for i in range(m-K+1):
            if max_align <= sum(choku[i:i+K]) + sum(saka[i-1:i+K]):
                max_align = sum(choku[i:i+K]) + sum(saka[i-1:i+K])
    else:
        for i in range(m-K+1):
            if max_align <= sum(choku[i:i+K]) + sum(saka[i:i+K+1]):
                max_align = sum(choku[i:i+K]) + sum(saka[i:i+K+1])
    print(max_align)
    break

Fixed submission:
N,K = map(int,input().split())
s = list(map(int,input()))
s.append(2)
start = s[0]
number = 1
choku = []
saka = [0]
for i in range(N):
    if s[i] == s[i+1]:
        number += 1
    else:
        if s[i] == 0:
            choku.append(number)
            number = 1
        else:
            saka.append(number)
            number = 1
choku.append(0)
saka.append(0)
while(1):
    max_align = 0
    m = len(choku)
    n = len(saka)
    if m <= K:
        print(N)
        break
    if start == 0: #最初が直立の場合
        aligns = [sum(choku[0:K]) + sum(saka[0:K+1])]
        for i in range(m-K-1):
            aligns.append(aligns[i] -choku[i]-saka[i] + choku[i+K] + saka[i+K+1])
        print(max(aligns))
    else:
        aligns = [sum(choku[0:K]) + sum(saka[1:K+2])]
        for i in range(m-K-1):
            aligns.append(aligns[i] -choku[i]-saka[i+1] + choku[i+K] + saka[i+K+2])
        print(max(aligns))
    break