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(str(input()))

first_index=0
last_index=0

res = 0
for f in range (first_index, n+1):
  for l in range (last_index, n+1):
    if f < l:
      continue
    check = 0
    for i in range(f, l+1):
      if s[i] == 0:
        check += 1
    if check <= k:
      if l-f > res:
        res = l-f

print(res)

aa

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

s = list(str(input()))

first_index=0
last_index=0

res = 0
for f in range (first_index, n):
  print("f: " + str(f))
  for l in range (last_index, n):
    print("  l: " + str(l))
    if f > l:
      continue
    check = 0
    for i in range(f, l):
      if s[i] == "0":
        check += 1
    if check <= k:
      if l-f > res:
        res = l-f +1

print(res)

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

s = list(str(input()))

first_index=0
last_index=0

res = 0
for f in range (first_index, n):
  print("f: " + str(f))
  for l in range (last_index, n):
    print("  l: " + str(l))
    if f > l:
      continue
    check = 0
    for i in range(f, l):
      if s[i] == "0":
        check += 1
    if check <= k:
      if l-f > res:
        res = l-f +1

print(res+1)

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

s = list(str(input()))

first_index=0
last_index=0

res = 0
for f in range (first_index, n):
  for l in range (last_index, n):
    if f < l:
      continue
    check = 0
    for i in (f, l):
      if s[i] == 0:
        check += 1
    if check <= k:
      if l-f > res:
        res = l-f

print(res)

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

first_index=0
last_index=0

res = 0
for f in range (first_index, n):
  print("f: " + str(f))
  for l in range (last_index, n+1):
    print("  l: " + str(l))
    if f > l:
      continue
    check = 0
    for i in range(f, l):
      if s[i] == "0":
        check += 1
    if check <= k:
      if l-f > res:
        res = l-f

print(res)

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

first_index=0
last_index=0

res = 0
for f in range (first_index, n):
  print("f: " + str(f))
  for l in range (last_index, n+1):
    print("  l: " + str(l))
    if f > l:
      continue
    check = 0
    for i in range(f, l):
      if s[i] == "0":
        check += 1
    if check <= k:
      if l-f > res:
        res = l-f

print(res)

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


array = []
now_num = 1
count = 0
for i in s:
  if now_num == int(i):
    count += 1
  else:
    array.append(count)
    count = 1
    now_num = 1 - now_num

if count != 0:
  array.append(count)

if len(array) % 2 == 0:
  array.append(0)

res = 0
add = 2 * k + 1
ans = 0
left = 0
right = 0
tmp = 0

for i in range(len(array))[::2]:
    next_left = i
    next_right = min(i+add, len(array))
    
    while next_left > left:
        tmp -= array[left]
        left += 1
    while next_right > right:
        tmp += array[right]
        right += 1
    ans = max(tmp,ans)

print(ans)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted