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):
N, K = map(int,input().split())
S = input()

zeros = []
num_zeros = 0
start = 0
cont = False
for i in range(N):
    s = int(S[i])
    if s == 0 and not cont:
        start = i
        cont = True
        num_zeros += 1
        zeros.append([start,1])
        continue

    elif s == 0 and cont:
        zeros[num_zeros-1][1] += 1
        continue

    elif s == 1:
        cont = False

print(zeros)

max_length = 0
search_num = len(zeros) - K + 1

#     if S[0] == "1":
#         max_length = 1
# else:

#         S_ = S
#         for k in range(K):



#         sub_max_length = 0
#         sub_sub_max_length = 0
#         for j in range(len(S_)):


#                 sub_sub_max_length += 1

#                 if sub_max_length < sub_sub_max_length:
#                     sub_max_length = sub_sub_max_length
#                 sub_sub_max_length = 0
#             if j == len(S_)-1:
#                 if sub_max_length < sub_sub_max_length:
#                     sub_max_length = sub_sub_max_length

#         if max_length < sub_max_length:
#             max_length = sub_max_length
print(max_length)

N, K = map(int,input().split())
S = input()

zeros = []
num_zeros = 0
start = 0
cont = False
for i in range(N):
    s = int(S[i])
    if s == 0 and not cont:
        start = i
        cont = True
        num_zeros += 1
        zeros.append([start,1])
        continue

    elif s == 0 and cont:
        zeros[num_zeros-1][1] += 1
        continue

    elif s == 1:
        cont = False

print(zeros)

max_length = 0
search_num = len(zeros) - K + 1
if search_num == 0:
    if S[0] == "1":
        max_length = 1
else:
    for i in range(search_num):
        S_ = S
        # for k in range(K):
        
        

        sub_max_length = 0
        sub_sub_max_length = 0
        for j in range(len(S_)):
            s = int(S_[j])
            if s == 1:
                sub_sub_max_length += 1
            elif s == 0:
                if sub_max_length < sub_sub_max_length:
                    sub_max_length = sub_sub_max_length
                sub_sub_max_length = 0
            if j == len(S_)-1:
                if sub_max_length < sub_sub_max_length:
                    sub_max_length = sub_sub_max_length

        if max_length < sub_max_length:
            max_length = sub_max_length
print(max_length)

N, K = map(int,input().split())
S = input()

pos = 0
i_s = [pos]
continue_s = S[0]
while True:
    pos += 1
    if pos == N :
        break
    s = S[pos]
    if continue_s == s:
        continue
    else:
        continue_s = s
        i_s.append(pos)


i_length = len(i_s) - 1
X = []
rev = K * 2
for n,i in enumerate(i_s):
    if S[i] == "1":
        if i_length - n >= rev-1:
            if i_length - n == rev-1:
                X.append(N-i)
            elif i_length - n == rev:
                X.append(N-i)
            else:
                X.append(i_s[n+rev+1]-i)

print(max(X))




N, K = map(int,input().split())
S = input()

i = 0
for j in range(N):
    if S[j] == "0" and (j==0 or S[j-1] == "1"):
        K -= 1
    if (K<0):
        if(S[i]=="0" and S[i+1] == "1"):
            K += 1
        i+=1

print(N-i)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted