Problem: N people are arranged in a row from left to right.  You are given a string S of length N consisting of `0` and `1`, and a positive integer K.  The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`.  You will give the following direction at most K times (possibly zero):  **Direction** : Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands.  Find the maximum possible number of **consecutive** people standing on hands after at most K directions.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()
zeros = [[0, 0]]

cnt = 0
for i in range(N):
    if S[i] == '0':
        if cnt == 0 and len(zeros) > 1:
            zeros[-1][1] = i-1
        cnt += 1
    else:
        if cnt > 0:
            zeros.append([cnt, 0])
            cnt = 0
if cnt > 0:
    zeros.append([cnt, N-1])
if zeros[-1][1] == 0:
    zeros[-1][1] = N-1

print(zeros)
l_zeros = len(zeros)
wa = 0
if K >= l_zeros-1:
    print(N)
    exit()
for i in range(l_zeros-K):
    print(zeros[i+K][1] - zeros[i][1] + 1)
    wa = max(zeros[i+K][1] - zeros[i][1] + 1, wa)

print(wa)

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()
zeros = [[0, 0]]

cnt = 0
for i in range(N):
    if S[i] == '0':
        if cnt == 0 and len(zeros) > 1:
            zeros[-1][1] = i-1
        cnt += 1
    else:
        if cnt > 0:
            zeros.append([cnt, 0])
            cnt = 0
if cnt > 0:
    zeros.append([cnt, N-1])
if zeros[-1][1] == 0:
    zeros[-1][1] = N-1

l_zeros = len(zeros)
wa = 0
if K >= l_zeros-1:
    print(N)
    exit()
for i in range(l_zeros-K):
    print(zeros[i+K][1] - zeros[i][1] + 1)
    wa = max(zeros[i+K][1] - zeros[i][1] + 1, wa)

print(wa)

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()

len_list = []

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        len_list.append(cnt)
        cnt = 1
    else:
        cnt += 1
#if cnt > 1:
len_list.append(cnt)

if S[0] == '1' or S[1] != '1':
    len_list = [0] + len_list
#print(len_list)
i = 0
wa = 0
while True:
    if i+2*K+1 < N:
        wa = max(wa, sum(len_list[i:i+2*K+1]))
    else:
        wa = max(wa, sum(len_list[i:]))
        break
    i += 1
print(wa)

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()

len_list = []
if S[0] == '1' and S[1] != '1':
    len_list.append(0)

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        len_list.append(cnt)
        cnt = 1
    else:
        cnt += 1
len_list.append(cnt)

#print(len_list)
i = 0
wa = 0
while True:
    if i+2*K+1 < N:
        wa = max(wa, sum(len_list[i:i+2*K+1]))
    else:
        wa = max(wa, sum(len_list[i:]))
        break
    i += 2
print(wa)

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

#from collections import defaultdict #d = defaultdict(int) d[key] += value
from itertools import accumulate 

N, K = mi()
S = input()

len_list = []
ind = 0
if S[0] == '0':
    #len_list[0] = 0
    len_list.append(0)
    #ind += 1

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        #len_list[ind] = cnt
        len_list.append(cnt)
        #ind += 1
        cnt = 1
    else:
        cnt += 1
#len_list[ind] = cnt
len_list.append(cnt)

l_list = len(len_list)
wa = [0] + list(accumulate(len_list))
ans = 0
i = 1
l_wa = len(wa)
while True:
    if i+2*K >= l_wa:
        ans = max(ans, wa[l_wa-1] - wa[i-1]) 
        break
    
        #ans = wa[i+2*K+1]
    ans = max(ans, wa[i+2*K] - wa[i-1]) 
    i += 2
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted