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

from collections import deque
from itertools import groupby

def gen(s):
  if s[:1] == '0':
  	yield 0
  for ke, g in groupby(s):
    yield len(list(g))
  if s[-1:] == '0':
    yield 0


mc = 0
ddd = deque()
r = 2 * k + 1
for p in gen(s):
  ddd.append(p)
  cd = len(ddd)
  if cd % 2 and cd > r:
    ddd.popleft()
    ddd.popleft()
  mc = max(mc, sum(ddd))
print(mc)


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

from itertools import groupby

def gen(s):
  if s[:1] == '0':
  	yield 0
  for ke, g in groupby(s):
    yield len(list(g))
  if s[-1:] == '0':
    yield 0


mc = 0
aaa = list(gen(s))
r = 2 * k + 1
if len(aaa) <= r:
  mc = sum(aaa)
else:
  for i in range(len(aaa) - r + 1):
    mc = max(mc, sum(aaa[i:i+r]))
print(mc)
  

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

from itertools import groupby, accumulate

def gen(s):
  if s[:1] == '0':
  	yield 0
  for ke, g in groupby(s):
    yield len(list(g))
  if s[-1:] == '0':
    yield 0


mc = 0
acc = list(accumulate(gen(s)))
r = 2 * k + 1
if len(acc) < r:
  mc = n
else:
  for i in range(1, len(acc)-r, 2):
    mc = max(mc, acc[i+r] - acc[i])
print(mc)


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

sr = k
tr = k + 1

ss = []
tt = []

if s[0] == '0':
  tt += [0]
  
mm = 0

c = 1
for i in range(1, n):
  if s[i-1:i+1] == '00':
    c += 1
  if s[i-1:i+1] == '10':
    tt += [c]
    if len(tt) > tr:
      tt = tt[1:]
    c = 1
  if s[i-1:i+1] == '11':
    c += 1
  if s[i-1:i+1] == '01':
    ss += [c]
    if len(ss) > tr:
      ss = ss[1:]
    c = 1
  if s[i] == '1':
    if len(tt) == tr:
      m = sum(ss) + sum(tt)
      if mm < m:
        mm = m
if s[n-1] == '0':
  ss += [c]
else:
  tt += [c]
  if len(tt) == tr:
    m = sum(ss) + sum(tt)
    if mm < m:
      mm = m
print(mm)


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

ss = []
tt = []

if s[0] == '0':
  tt += [0]

c = 1
for i in range(1, n):
  if s[i-1:i+1] == '00':
    c += 1
  if s[i-1:i+1] == '10':
    tt += [c]
    c = 1
  if s[i-1:i+1] == '11':
    c += 1
  if s[i-1:i+1] == '01':
    ss += [c]
    c = 1
if s[n-1] == '0':
  ss += [c]
else:
  tt += [c]
  
print(ss)
print(tt)

sr = k
tr = k + 1

sl = len(ss)
tl = len(tt)

mm = 0
for i in range(tl):
  try:
    m = sum(ss[i:i+sr]) + sum(tt[i:i+tr])
    if mm < m:
      mm = m
  except:
    pass
print(mm)


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

from collections import deque
from itertools import groupby

def gen(s):
  if s[:1] == '0':
  	yield 0
  for ke, g in groupby(s):
    yield len(list(g))
  if s[-1:] == '0':
    yield 0


mc = 0
ddd = deque()
r = 2 * k + 1
for p in gen(s):
  ddd.append(p)
  cd = len(ddd)
  if cd % 2 and cd > r:
    ddd.popleft()
    ddd.popleft()
    mc = max(mc, sum(ddd))
print(mc)

    

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

if s[0] == '0':
  t += '0'
c = 1
for i in range(1, n):
  if s[i-1] == '0' and s[i] == '0':
    c += 1
  if s[i-1] == '1' and s[i] == '0':
    t += str(c)
    c = 1
  if s[i-1] == '0' and s[i] == '1':
    t += str(c)
    c = 1
  if s[i-1] == '1' and s[i] == '1':
    c += 1
t += str(c)
t = list(map(int, t))
print(t)


r = 2 * k + 1
gs = []
for i in range(0,n,2):
  if i + r < n:
    gs.append(sum(t[i:i+r]))
print(max(gs))


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

from itertools import groupby, accumulate

def gen(s):
  if s[:1] == '0':
  	yield 0
  for ke, g in groupby(s):
    yield len(list(g))
  if s[-1:] == '0':
    yield 0


mc = 0
acc = list(accumulate(gen(s)))
r = 2 * k + 1
if len(acc) < r:
  mc = n
else:
  for i in range(0, len(acc)-r+1, 2):
    if i == 0:
      mc = max(mc, acc[i+r-1])
    else:
      mc = max(mc, acc[i+r-1] - acc[i-1])
print(mc)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted