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=str(input())
s=s+'e'
arr=[[] for _ in range(3)]
count=1
for i in range(n):
  if s[i]==s[i+1]:
    count+=1
  else:
    if s[i]=='1':
      arr[0].append(count)
      count=1
    else:
      arr[1].append(count)
      count=1
if len(arr[1])<=k:
  print(n)
else:
  if len(arr[0])==len(arr[1]):
    arr[0].append(0)
  elif len(arr[0])<len(arr[1]):
    arr[0].append(0)
    arr[0].append(0)
  print(arr[0])
  print(arr[1])
  tmp=0
  sum=0
  count=0
  max=0
  flag=False
  for i in range(len(arr[1])):
    sum+=arr[0][i]
    sum+=arr[1][i]
    count+=1
    if flag:      
      sum-=arr[0][i-k]
      sum-=arr[1][i-k]
    if count==k:
      tmp=sum
      tmp+=arr[0][i+1]
      if tmp>max:
        max=tmp
      count-=1
      flag=True
  print(max)

n,k=map(int,input().split())
s=input()
s+='e'
arr=[]
arr2=[]
count=1
for i in range(n):
  if s[i]==s[i+1]:
    count+=1
  else:
    arr.append(count)
    arr2.append(s[i])
    count=1
print(arr)
print(arr2)
tmp=max([arr[i] for i in range(len(arr))])
for i in range(len(arr)-k*2):
  if arr2[i]=='1':
    if tmp<sum(arr[i:i+k*2+1]):
      tmp=sum(arr[i:i+k*2+1])
  else:
    if tmp<sum(arr[i:i+k*2]):
      tmp=sum(arr[i:i+k*2])
print(tmp)

n,k=map(int,input().split())
s=str(input())
s=s+'e'
arr=[[] for _ in range(2)]
count=1
for i in range(n):
  if s[i]==s[i+1]:
    count+=1
  else:
    if s[i]=='1':
      arr[0].append(count)
      count=1
    else:
      arr[1].append(count)
      count=1
if len(arr[1])<=k:
  print(n)
else:
  if len(arr[0])==len(arr[1]):
    arr2=[0]
    arr2.extend(arr[0])
    arr[0]=arr2
    arr[1].append(0)
  elif len(arr[0])<len(arr[1]):
    arr2=[0]
    arr2.extend(arr[0])
    arr[0]=arr2
    arr[0].append(0)
    arr[1].append(0)
  tmp=0
  sum=0
  count=0
  max=0
  flag=False
  for i in range(1,len(arr[1])-1):
    sum+=arr[0][i]
    sum+=arr[1][i]
    count+=1
    if flag:      
      sum-=arr[0][i-k]
      sum-=arr[1][i-k]
    if count==k:
      tmp=sum
      tmp+=arr[0][i+1]
      if tmp>max:
        max=tmp
      count-=1
      flag=True
  print(max)

n,k=map(int,input().split())
s=str(input())
s=s+'e'
arr=[[] for _ in range(3)]
count=1
for i in range(n):
  if s[i]==s[i+1]:
    count+=1
  else:
    if s[i]=='1':
      arr[0].append(count)
      count=1
    else:
      arr[1].append(count)
      count=1
print(arr[0])
print(arr[1])
if len(arr[1])<=k:
  print(n)
else:
  if len(arr[0])==len(arr[1]):
    arr[0].append(0)
  elif len(arr[0])<len(arr[1]):
    arr[0].append(0)
    arr[0].append(0)
  tmp=0
  sum=0
  count=0
  max=0
  flag=False
  for i in range(len(arr[1])):
    sum+=arr[0][i]
    sum+=arr[1][i]
    count+=1
    if flag:      
      sum-=arr[0][i-k]
      sum-=arr[1][i-k]
    if count==k:
      tmp=sum
      tmp+=arr[0][i+1]
      if tmp>max:
        max=tmp
      count-=1
      flag=True
print(max)

n,k=map(int,input().split())
s=str(input())
s=s+'e'
arr=[[] for _ in range(2)]
count=1
for i in range(n):
  if s[i]==s[i+1]:
    count+=1
  else:
    if s[i]=='1':
      arr[0].append(count)
      count=1
    else:
      arr[1].append(count)
      count=1
if len(arr[1])<=k:
  print(n)
else:
  if len(arr[0])==len(arr[1]):
    arr2=[0]
    arr2.extend(arr[0])
    arr[0]=arr2
    arr[1].append(0)
  elif len(arr[0])<len(arr[1]):
    arr2=[0]
    arr2.extend(arr[0])
    arr[0]=arr2
    arr[0].append(0)
    arr[1].append(0)
  else:
    arr[1].append(0)
  print(arr[0])
  print(arr[1])
  tmp=0
  sum=0
  count=0
  max=0
  flag=False
  for i in range(len(arr[1])-1):
    sum+=arr[0][i]
    sum+=arr[1][i]
    count+=1
    if flag:      
      sum-=arr[0][i-k]
      sum-=arr[1][i-k]
    if count==k:
      tmp=sum
      tmp+=arr[0][i+1]
      if tmp>max:
        max=tmp
      count-=1
      flag=True
  print(max)

n,k=map(int,input().split())
s=str(input())
s=s+'e'
arr=[[] for _ in range(2)]
count=1
for i in range(n):
  if s[i]==s[i+1]:
    count+=1
  else:
    if s[i]=='1':
      arr[0].append(count)
      count=1
    else:
      arr[1].append(count)
      count=1
if len(arr[1])<=k:
  print(n)
else:
  if s[0]=='0':
    arr2=[0]
    arr2.extend(arr[0])
    arr[0]=arr2
  arr[0].append(0)
  arr[1].append(0)
  tmp=0
  sum=0
  count=0
  max=0
  flag=False
  for i in range(len(arr[1])-1):
    sum+=arr[0][i]
    sum+=arr[1][i]
    count+=1
    if flag:      
      sum-=arr[0][i-k]
      sum-=arr[1][i-k]
    if count==k:
      tmp=sum
      tmp+=arr[0][i+1]
      if tmp>max:
        max=tmp
      count-=1
      flag=True
  print(max)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted