Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()

change_points = [i for i in range(n) if i == 0 or s[i-1] != s[i]]
max_ = 0
for i in range(len(change_points)):
    count = 0
    cur_k = 0
    for j in range(i, len(change_points)):
        p = change_points[j]
        if s[p] == '1':
            if j < len(change_points) - 1:
                count += change_points[j+1] - p
            else:
                count += len(s) - p
        else:
            if cur_k < k:
                cur_k += 1
                if j < len(change_points) - 1:
                    count += change_points[j+1] - p
                else:
                    count += len(s) - p
            else:
                break

    if count > max_:
        max_ = count
print(max_)


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

change_points = [i for i in range(n) if i == 0 or s[i-1] != s[i]]
change_points.append(n)
max_ = 0
for i, p in enumerate(change_points):
    if i == len(change_points) - 1:
        continue
    if s[p] == '0':
        if i == 0:
            idx = min(i + 2 * k, len(change_points) - 1)
            tmp = change_points[idx] - p
        else:
            continue
    else:
        idx = min(i + 2 * k + 1, len(change_points) - 1)
        tmp = change_points[idx] - p
    if tmp > max_:
        max_ = tmp

print(max_)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()

change_points = [i for i in range(n) if i == 0 or s[i-1] != s[i]]
max_ = 0
for i in change_points:
    count = 0
    cur_k = 0
    is_zero = False
    for c in s[i:]:
        if len(s[i:]) < max_:
            break
        if c == '1':
            count += 1
            is_zero = False
        else:
            if is_zero:
                count += 1
            elif cur_k < k:
                cur_k += 1
                count += 1
                is_zero = True
            else:
                break
    if count > max_:
        max_ = count
print(max_)


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

change_points = [i for i in range(n) if i == 0 or s[i-1] != s[i]]
change_points.append(n)
max_ = 0
for i, p in enumerate(change_points):
    if i == len(change_points) - 1:
        continue
    if s[p] == '0':
        if i == 0:
            idx = min(i + 2 * k, len(change_points) - 1)
            tmp = change_points[idx] - p
        else:
            continue
    else:
        idx = min(i + 2 * k + 1, len(change_points) - 1)
        tmp = change_points[idx] - p
    if tmp > max_:
        max_ = tmp

print(max_)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()

max_ = 0
for i in range(n):
    count = 0
    cur_k = 0
    is_zero = False
    for c in s[i:]:
        if len(s[i:]) < max_:
            break
        if c == '1':
            count += 1
            is_zero = False
        else:
            if is_zero:
                count += 1
            elif cur_k < k:
                cur_k += 1
                count += 1
                is_zero = True
            else:
                break
    if count > max_:
        max_ = count
print(max_)


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

change_points = [i for i in range(n) if i == 0 or s[i-1] != s[i]]
change_points.append(n)
max_ = 0
for i, p in enumerate(change_points):
    if i == len(change_points) - 1:
        continue
    if s[p] == '0':
        if i == 0:
            idx = min(i + 2 * k, len(change_points) - 1)
            tmp = change_points[idx] - p
        else:
            continue
    else:
        idx = min(i + 2 * k + 1, len(change_points) - 1)
        tmp = change_points[idx] - p
    if tmp > max_:
        max_ = tmp

print(max_)