Buggy python submission (verdict: Time Limit Exceeded):
import sys

if __name__ == '__main__':
    N, K = map(lambda x:int(x), sys.stdin.readline().split())
    S = list(map(lambda x: int(x), list(sys.stdin.readline().rstrip())))
    start, end = 0, 0
    bStart, bEnd = 0, 0
    while True:
        # S[start:end]にある孤立した0がK個以下か
        sub = S[start:end]
        # print(S, start, end)
        # 11001101
        # print(start, end)
        z = 0
        prev = 1
        for i in range(len(sub)):
            if prev == 1 and sub[i] == 0:
                z += 1
            prev = sub[i]
        # print(z)
        # exit()
        # 全員を起立させられるので，広げる
        if z <= K:
            if bEnd - bStart < end - start:
                bStart, bEnd = start, end
                # print(S, start, end)
            
            end += 1
            if end == len(S) + 1:
                break
        # 反転しても逆立ちが残るので，狭める
        else:
            start += 1
    S[bStart:bEnd] = [1 for _ in range(bStart, bEnd)]

    o, maxO = 0, 0
    prev = 1
    for s in S:
        # print(prev, s)
        if prev == 1 and s == 0:
            if o > maxO:
                maxO = o
            o = 0
        elif s == 1:
            o += 1
        prev = s
    else:
        if o > maxO:
            maxO = o

    print(maxO)

Fixed submission:
import sys
from datetime import datetime

if __name__ == '__main__':
    N, K = map(lambda x:int(x), sys.stdin.readline().split())
    S = list(map(lambda x: int(x), list(sys.stdin.readline().rstrip())))
    start, end = 0, 0
    bStart, bEnd = 0, 0
    # 01010110
    #  * *
    # 広げる時:
    #   前回のz=1
    #   前回のs_end=1
    #   今回広がったもの=0
    #   今回のz=2
    # 狭める時:
    #   前回のz=1
    #   前回のs_start=1
    #   今回狭まったもの=0
    #   今回のz=1
    extend = True
    
    z = 0
    # print(S)
    while True:
        # assert start <= end
        # print(start, end, 'z:', z)
        
        # S[start:end]にある孤立した0がK個以下か
        # prev = 1
        # z = 0
        # for i in range(start, end):
        #     if prev == 1 and S[i] == 0:
        #         z += 1
        #     prev = S[i]
        if extend:
            end_back = 1 if end == 0 else S[end-1]
            if end_back == 1 and S[end] == 0:
                z += 1
        else:
            start_back = 1 if start == 0 else S[start-1]
            if start_back == 0 and S[start] == 1:
                z -= 1
        # input()
        # 全員を起立させられるので，広げる
        # print(z)
        if z <= K:
            if bEnd - bStart < end - start:
                bStart, bEnd = start, end
            end += 1
            if end == len(S):
                break
            extend = True
        # 反転しても逆立ちが残るので，狭める
        else:
            start += 1
            if start == len(S)-1:
                break
            extend = False
    bEnd += 1
    S[bStart:bEnd] = [1 for _ in range(bStart, bEnd)]
    # print(S, bStart, bEnd)

    o, maxO = 0, 0
    prev = 1
    for s in S:
        # print(prev, s)
        if prev == 1 and s == 0:
            if o > maxO:
                maxO = o
            o = 0
        elif s == 1:
            o += 1
        prev = s
    else:
        if o > maxO:
            maxO = o

    print(maxO)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

if __name__ == '__main__':
    N, K = map(lambda x:int(x), sys.stdin.readline().split())
    S = list(map(lambda x: int(x), list(sys.stdin.readline().rstrip())))
    # print(S)
    start, end = 0, 0
    bStart, bEnd = 0, 0
    # print(S)
    while True:
            # S[start:end]にある孤立した0がK個以下か
        sub = S[start:end]
        # print(S, start, end)
        # 11001101
        # print(start, end)
        z = 0
        prev = 1
        for i in range(len(sub)):
            if prev == 1 and sub[i] == 0:
                z += 1
            prev = sub[i]
        # print(z)
        # exit()
        # 全員を起立させられるので，広げる
        if z <= K:
            if bEnd - bStart < end - start:
                bStart, bEnd = start, end
                # print(S, start, end)
            
            end += 1
            if end == len(S) + 1:
                break
        # 反転しても逆立ちが残るので，狭める
        else:
            start += 1
    # print(S)
    S[bStart:bEnd] = [1 for _ in range(bStart, bEnd)]
    # print(S, bStart, bEnd)

    o, maxO = 0, 0
    prev = 1
    for s in S:
        # print(prev, s)
        if prev == 0 and s == 1:
            o = 1
        elif prev == 1 and s == 0:
            if o > maxO:
                maxO = o
        elif prev == 1 and s == 1:
            o += 1
        prev = s
    else:
        if o > maxO:
            maxO = o

    print(maxO)

Fixed submission:
import sys
from datetime import datetime

if __name__ == '__main__':
    N, K = map(lambda x:int(x), sys.stdin.readline().split())
    S = list(map(lambda x: int(x), list(sys.stdin.readline().rstrip())))
    start, end = 0, 0
    bStart, bEnd = 0, 0
    # 01010110
    #  * *
    # 広げる時:
    #   前回のz=1
    #   前回のs_end=1
    #   今回広がったもの=0
    #   今回のz=2
    # 狭める時:
    #   前回のz=1
    #   前回のs_start=1
    #   今回狭まったもの=0
    #   今回のz=1
    extend = True
    
    z = 0
    # print(S)
    while True:
        # assert start <= end
        # print(start, end, 'z:', z)
        
        # S[start:end]にある孤立した0がK個以下か
        # prev = 1
        # z = 0
        # for i in range(start, end):
        #     if prev == 1 and S[i] == 0:
        #         z += 1
        #     prev = S[i]
        if extend:
            end_back = 1 if end == 0 else S[end-1]
            if end_back == 1 and S[end] == 0:
                z += 1
        else:
            start_back = 1 if start == 0 else S[start-1]
            if start_back == 0 and S[start] == 1:
                z -= 1
        # input()
        # 全員を起立させられるので，広げる
        # print(z)
        if z <= K:
            if bEnd - bStart < end - start:
                bStart, bEnd = start, end
            end += 1
            if end == len(S):
                break
            extend = True
        # 反転しても逆立ちが残るので，狭める
        else:
            start += 1
            if start == len(S)-1:
                break
            extend = False
    bEnd += 1
    S[bStart:bEnd] = [1 for _ in range(bStart, bEnd)]
    # print(S, bStart, bEnd)

    o, maxO = 0, 0
    prev = 1
    for s in S:
        # print(prev, s)
        if prev == 1 and s == 0:
            if o > maxO:
                maxO = o
            o = 0
        elif s == 1:
            o += 1
        prev = s
    else:
        if o > maxO:
            maxO = o

    print(maxO)