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 numpy as np

def main():
    n,k = map(int,input().split())
    s = input()
    li = np.array([])
    count = 1


    for i in range(n-1):
        if s[i] == s[i+1]:
            count += 1
        else:
            li = np.append(li,count)
            count = 1
    li = np.append(li,count)

    m = len(li)

    if s[0] == '1':
        t = int(m/2)
        if k >= t:
            print(sum(li))
        else:
            for i in range(t-k+1):
                max1 = max(np.sum(li[2*i:2*(i+k)+1]),max1)
            print(max1)
    else:
        t = int(m/2+1)
        if k >= t:
            print(sum(li))
        else:
            max1 = sum(li[:2*k])
            for i in range(t-k):
                max1 = max(np.sum(li[2*i+1:2*(i+k)+2]),max1)
            print(max1)
main()


n,k = map(int,input().split())
s = input()
li = [0]
count = 1

for i in range(n-1):
    if s[i] != s[i+1]:
        li.append(count)
    count += 1
li.append(count)

m = len(li)

if s[0] == '1':
    t = int(m/2-1)
    if k >= t:
        print(n)
    else:
        max1 = 0
        for i in range(t-k+1):
            max1 = max(li[2*(i+k)+1] - li[2*i],max1)
        print(max1)
else:
    t = int(m/2)
    if k >= t:
        print(n)
    else:
        max1 = li[2*k]
        for i in range(t-k):
            max1 = max(li[2*(i+k+1)] - li[2*i+1],max1)
        print(max1)


n,k = map(int,input().split())
s = input()
li = [0]
count = 1

for i in range(n-1):
    if s[i] != s[i+1]:
        li.append(count)
    count += 1
li.append(count)

print(li)

m = len(li)

if s[0] == '1':
    t = int(m/2-1)
    if k >= t:
        print(n)
    else:
        max1 = 0
        for i in range(t-k+1):
            max1 = max(li[2*(i+k)+1] - li[2*i],max1)
        print(max1)
else:
    t = int(m/2)
    if k >= t:
        print(n)
    else:
        max1 = li[2*k]
        for i in range(t-k):
            max1 = max(li[2*(i+k+1)] - li[2*i+1],max1)
        print(max1)


n,k = map(int,input().split())
s = input()
li = [0]
count = 1

for i in range(n-1):
    if s[i] != s[i+1]:
        li.append(count)
    count += 1
li.append(count)

m = len(li)

if s[0] == '1':
    li.append(li[-1])
    li.append(li[-1])
    t = int(m/2-1)
    if k >= t:
        print(n)
    else:
        max1 = 0
        for i in range(t-k+2):
            max1 = max(li[2*(i+k)+1] - li[2*i],max1)
        print(max1)
else:
    li.append(li[-1])
    t = int(m/2)
    if k >= t:
        print(n)
    else:
        max1 = li[2*k]
        for i in range(t-k):
            max1 = max(li[2*(i+k+1)] - li[2*i+1],max1)
        print(max1)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted