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 = list(input())

nums = []
now = 1
count = 0
for i in range(len(S)):
    if S[i] is str(now):
        count += 1
    else:
        nums.append(count)
        now = 1 - now
        count = 1
if count != 0:
    nums.append(count)
if len(nums) % 2 == 0:
    nums.append(0)  

add = 2 * K + 1

sum = [0] * (len(nums)+1)
for i in range(len(nums)):
    sum[i+1] = sum[i] + nums[i]
ans = 0
print(list(range(0,len(nums), 2)))
for i in range(0,len(nums), 2):
    left = i
    right = min(i + add, len(nums))
    tmp = sum[right] - sum[left]
    ans = max(tmp, ans)

print(ans)

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

nums = []
now = 1
count = 0
for i in range(len(S)):
    if S[i] is str(now):
        count += 1
    else:
        nums.append(count)
        now = 1 - now
        count = 1
if count != 0:
    nums.append(count)
if len(nums) % 2 == 0:
    nums.append(0)  

add = 2 * K + 1

sum = [0] * (len(nums)+1)
for i in range(len(nums)):
    sum[i+1] = sum[i] + nums[i]
ans = 0

for i in range(0,len(nums), 2):
    left = i
    right = min(i + add, len(nums))
    tmp = sum[right] - sum[left]
    ans = max(tmp, ans)

print(ans)

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

nums = []
now = 1
count = 0
for i in range(len(S)):
    if S[i] == str(now):
        count += 1
    else:
        nums.append(count)
        now = 1 - now
        count = 1
if count != 0:
    nums.append(count)
if len(nums) % 2 == 0:
    nums.append(0)  

add = 2 * K + 1

sum = []
sum.append(0)
for i in range(len(nums)+1):
    sum.append(sum[i] + nums[i])

ans = 0

for i in range(len(nums),2):
    left = i
    right = min(i + add, len(nums))
    tmp = sum[right] - sum[left] 
    ans = max(tmp, ans)

print(ans)

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

nums = []
now = 1
count = 0
for i in range(len(S)):
    if S[i] == str(now):
        count += 1
    else:
        nums.append(count)
        now = 1 - now
        count = 1
if count != 0:
    nums.append(count)
if len(nums) % 2 == 0:
    nums.append(0)  

add = 2 * k + 1

sum = []
sum.append(0)
for i in range(len(nums) + 1):
    sum[i+1] = sum[i] + nums[i]

ans = 0

for i in range(len(nums),2):
    left = i
    right = min(i + add, len(nums))
    tmp = sum[right] - sum[left] 
    ans = max(tmp, ans)

print(ans)

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

nums = []
now = 1
count = 0
for i in range(len(S)):
    if S[i] == str(now):
        count += 1
    else:
        nums.append(count)
        now = 1 - now
        count = 1
if count != 0:
    nums.append(count)
if len(nums) % 2 == 0:
    nums.append(0)  

add = 2 * K + 1

sum = []
sum.append(0)
for i in range(len(nums)):
    sum.append(sum[i] + nums[i])

ans = 0

for i in range(len(nums),2):
    left = i
    right = min(i + add, len(nums))
    tmp = sum[right] - sum[left] 
    ans = max(tmp, ans)

print(ans)

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

nums = []
now = 1
count = 0
for i in range(len(S)):
    if S[i] == str(now):
        count += 1
    else:
        nums.append(count)
        now = 1 - now
        count = 1
if count != 0:
    nums.append(count)
if len(nums) % 2 == 0:
    nums.append(0)  

add = 2 * K + 1

sum = []
sum.append(0)
for i in range(len(nums)):
    sum.append(sum[i] + nums[i])

ans = 0

for i in range(len(nums),2):
    left = i
    right = min(i + add, len(nums))
    tmp = sum[right] - sum[left] 
    ans = max(tmp, ans)

print(ans)

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

nums = []
now = 1
count = 0
for i in range(len(S)):
    if S[i] == str(now):
        count += 1
    else:
        nums.append(count)
        now = 1 - now
        count = 1
if count != 0:
    nums.append(count)
if len(nums) % 2 == 0:
    nums.append(0)  

add = 2 * k + 1

sum = []
sum.append(0)
for i in range(len(nums) + 1):
    sum[i+1] = sum[i] + nums[i]

ans = 0

for i in range(len(nums) / 2):
    left = i
    right = min(i + add, len(nums))
    tmp = sum[right] - sum[left]
    ans = max(tmp, ans)

print(ans)

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

nums = []
now = 1
count = 0
for i in range(len(S)):
    if S[i] == str(now):
        count += 1
    else:
        nums.append(count)
        now = 1 - now
        count = 1
if count != 0:
    nums.append(count)
if len(nums) % 2 == 0:
    nums.append(0)

add = 2 * K + 1

sum = [0] * (len(nums)+1)

for i in range(len(nums)):
    sum[i+1] = sum[i] + nums[i]
ans = 0
for i in range(0, len(nums), 2):
    left = i
    right = min(i + add, len(nums))
    tmp = sum[right] - sum[left]
    ans = max(tmp, ans)

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted