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

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

S = input()
S = [int(i) for i in S]

array = np.zeros(len(S))


for i in range(len(S)-1):
    if S[i] == S[i+1]:
        array[i] = 0
    else:
        array[i] = 1

print(array)

res = np.cumsum(array)
print(res)
ma = int(np.max(res))

count = 0
count_old = 0

for i in range(ma-K+1):
    for j in range(len(S)):
        #print(i,j)
        if res[j] >= i and res[j] <= K+1+i:
            count += 1
    if count_old < count:
        count_old = count
        #print(count_old,i)
    #print(count_old,K+i,i,count)        
    count = 0

        
print(count_old)

import numpy as np

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

S = input()
S = [int(i) for i in S]

array = np.zeros(len(S))


for i in range(len(S)-1):
    if S[i] == S[i+1]:
        array[i] = 0
    else:
        array[i] = 1

#print(array)

res = np.cumsum(array)
#print(res)
ma = int(np.max(res))

count = 0
count_old = 0

for i in range(ma-K+1):
    for j in range(len(S)):
        #print(i,j)
        if res[j] >= i and res[j] <= K+1+i:
            count += 1
    if count_old < count:
        count_old = count
        #print(count_old,i)
    #print(count_old,K+i,i,count)        
    count = 0

        
print(count)

import numpy as np

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

S = input()
S = [int(i) for i in S]

array = np.zeros(len(S))


for i in range(len(S)-1):
    if S[i] == S[i+1]:
        array[i] = 0
    else:
        array[i] = 1

#print(array)

res = np.cumsum(array)
#print(res)
ma = int(np.max(res))

count = 0
count_old = 0

for i in range(ma-K+1):
    for j in range(len(S)):
        #print(i,j)
        if res[j] >= i and res[j] <= K+1+i:
            count += 1
    if count_old < count:
        count_old = count
        #print(count_old,i)
    #print(count_old,K+i,i,count)        
    count = 0

        
print(count_old)

import numpy

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

ans = 0
cnt = 1
l = []


for i in range(n):
    if i == n-1:
        l.append(cnt)
        break
    if s[i] == s[i+1]:
        cnt += 1
    else:
        l.append(cnt)
        cnt = 1


if s[0] == '0':
    l.insert(0,0)

#print(s[-1] == '0')

if s[-1] == '0':
    l.append(0)
    
l_rui = numpy.cumsum(l)
l_rui = numpy.insert(l_rui,0,0)

k = 2*k

for i in range(n):
    if 2*i >= len(l_rui):
        break
    elif k+1+2*i >= len(l_rui):
        ans = max(ans, l_rui[-1] - l_rui[2*i])
    else:
        ans = max(ans, l_rui[k+1+2*i] - l_rui[2*i])

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted