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 = list(map(int, input().split()))
S = input()

def search(first, count):
  change = 0
  past = S[first]
  for i in range(first, len(S)):
    now = S[i]
    if past != now:
      change += 1
      if change == count*2:
        for j in range(i, len(S)):
          if S[first] != S[j]:
            return j-first
        return len(S)-first
    past = S[i]
  return len(S)-first

max_len = 0
past = ""
for i in range(len(S)):
  now = S[i]
  if past != now:
    
    max_len = max([search(i, K), max_len])
  past = S[i] 
  

#print(N, K, S)
print(max_len)

N, K = list(map(int, input().split()))
S = input()
 
S += "X"
j = 0
count = 1
change = [] if S[0] != "0" else [0]
for j in range(len(S)-1):
  if S[j:j+2] == "10":
    change.append(count)
    count = 0
  elif S[j:j+2] == "01":
    change.append(count)
    count = 0
  count += 1

change.append(count-1)
#print(change)
max_len = 0
for i in (0, len(change), 2):
  max_len = max([sum(change[i:i+2*K+2]), max_len])
  
print(max_len)

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

def search(first, count):
  change = 0
  past = S[first]
  for i in range(first, len(S)):
    now = S[i]
    if past != now:
      change += 1
      if change == count*2:
        for j in range(i, len(S)):
          if S[first] != S[j]:
            return j-first
        return len(S)-first
    past = S[i]
  return len(S)-first

max_len = 0
past = ""
for i in range(len(S)):
  now = S[i]
  if past != now:
    
    max_len = max([search(i, K), max_len])
  past = S[i] 
  
print(max_len)

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

def search(first, count):
  change = 0
  past = S[first]
  for i in range(first, len(S)):
    now = S[i]
    if past != now:
      change += 1
      if change == count*2:
        for j in range(i-1, len(S)):
          if S[first] != S[j]:
            return j-first
    past = S[i] 
  return len(S)-first

max_len = 0
past = ""
for i in range(len(S)):
  now = S[i]
  if past != now:
    
    max_len = max([search(i, K), max_len])
  past = S[i] 
  

#print(N, K, S)
print(max_len)

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

def search(first, count):
  change = 0
  past = S[first]
  for i in range(first, len(S)):
    now = S[i]
    if past != now:
      change += 1
      if change == count*2:
        for j in range(i, len(S)):
          if S[first] != S[j]:
            return j-first
    past = S[i] 
  return len(S)-first

max_len = 0
past = ""
for i in range(len(S)):
  now = S[i]
  if past != now:
    
    max_len = max([search(i, K), max_len])
  past = S[i] 
  

#print(N, K, S)
print(max_len)

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

def search(first, count):
  change = 0
  past = S[first]
  for i in range(first, len(S)):
    now = S[i]
    if past != now:
      change += 1
      if change == count*2:
        for j in range(i+1, len(S)):
          if S[first] != S[j]:
            return j-first
    past = S[i] 
  return len(S)-first

max_len = 0
past = ""
for i in range(len(S)):
  now = S[i]
  if past != now:
    
    max_len = max([search(i, K), max_len])
  past = S[i] 
  

#print(N, K, S)
print(max_len)

N, K = list(map(int, input().split()))
S = input()
 
S += "X"
j = 0
count = 1
change = [] if S[0] != "0" else [0]
for j in range(len(S)-1):
  if S[j:j+2] == "10":
    change.append(count)
    count = 0
  elif S[j:j+2] == "01":
    change.append(count)
    count = 0
  count += 1

change.append(count-1)
#print(change)
K = 2*K + 1
max_len = max([sum(change[i:i+K]) for i in range(0, len(change), 2)])
  

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

def search(first, count):
  change = 0
  past = S[first]
  for i in range(first, len(S)):
    now = S[i]
    if past != now:
      change += 1
      if change == count*2:
        for j in range(i, len(S)):
          if S[first] != S[j]:
            return j-first
    past = S[i] 
  return len(S)-first

max_len = 0
past = ""
for i in range(len(S)):
  now = S[i]
  if past != now:
    
    max_len = max([search(i, K), max_len])
  past = S[i] 
  

#print(N, K, S)
print(max_len)

N, K = list(map(int, input().split()))
S = input()
 
S += "X"
i = 0
j = 0
max_len = 0
change = 0 if S[0] != "0" else 1
while j < len(S)-1:
  if change <= K:
    #print(i, j)
    max_len = max([j-i+1, max_len])
    if S[j:j+2] == "10":
      change += 1
    j += 1
  else:
    if S[i:i+2] == "01":
      change -= 1
    i += 1

print(max_len)
  

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted