TnT/Multi_CodeNet4Repair huggingface dataset:
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=[int(i) for i in input().split()]
S=input()
cur=0
line=[]

for i in range(len(S)):
	if i==0:
		if S[0]=="0":
			line.append(0)
		line.append(1)
	else:
		if S[i-1]!=S[i]:
			line.append(1)
		else:
			line[-1]+=1
c=0
for i in range(len(line)):

	if i==0:
		if 2*K+1<=len(line):
			s=sum(line[i:2*K+1])
			c=s
		else:
			s=sum(line[i:])
			c=s
	elif i%2==0:
		if i+2*K<=len(line):
			s=s-line[i-2]-line[i-1]+line[i+2*K-1]+line[i+2*K]
			c=max(c,s)
		else:
			c=max(c,sum(line[i:]))
			break
print(c)

N,K=[int(i) for i in input().split()]
S=input()
cur=0
line=[]

for i in range(len(S)):
	if i==0:
		if S[0]=="0":
			line.append(0)
		line.append(1)
	else:
		if S[i-1]!=S[i]:
			line.append(1)
		else:
			line[-1]+=1
c=0
for i in range(len(line)):

	if i==0:
		if i+2*K+1<=len(line):
			s=sum(line[i:2*K+1])
			c=s
		else:
			s=sum(line[i:])
			c=s
	elif i%2==0:
		if i+2*K+1<=len(line):
			s=s-line[i-2]-line[i-1]+line[i+2*K-1]+line[i+2*K]
			c=max(c,s)
		else:
			c=max(c,sum(line[i:]))
			break
print(c)

Verdicts: Runtime Error

Accepted
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):
from collections import deque
n, k = map(int, input().split())
s = list(input())
lis = []
val = [0, 0]
for i in range(n):
    if s[i] == '1' and s[i-1] == '0':
         lis.append(val)
         val = [0,0]
    val[int(s[i])] += 1
lis.append(val)
lis2 = []
val = [0,0]
s.reverse()
for i in range(n):
    if s[i] == '1' and s[i-1] == '0':
         lis2.append(val)
         val = [0,0]
    val[int(s[i])] += 1
lis2.append(val)

print(lis)
print(lis2)
if len(lis) - k > 0:
    l = 0
    r = 0
    for i in range(len(lis) - k):
        if sum(lis[l]) < sum(lis2[r]):
            n -= sum(lis[l])
            l += 1
        else:
            n -= sum(lis2[r])
            r += 1
print(n)


n, k = map(int, input().split())
s = input()
lis = [0]
j = 0
if s[0] == '0':
    lis.append(0)
    j = 1
#print(len(lis))
lis[j] += 1
for i in range(1,n):
    #print(len(lis))
    if s[i] != s[i-1]:
        j += 1
        lis.append(0)
    lis[j] += 1
if s[n-1] == '0':
    lis.append(0)
#print(lis)
com = [0] * (len(lis) + 1)
for i in range(len(lis)):
    com[i+1] = com[i] + lis[i]
#print(com)
ans = 0
for i in range(len(lis)):
    if i % 2 == 0:
        ans = max(ans,lis[i])
l = 0
while l < len(com):
    r = l + (2 * k + 1)
    if r >= len(com):
        r = len(com) - 1
    ans = max(ans,com[r] - com[l])
    l += 2
print(ans)


Verdicts: Wrong Answer

Accepted
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):
from itertools import*
from numpy import*
n,k=map(int,input().split())
k2=k+1
s=input()
if len(s)==1:
    if s=="1":
        print(1)
    else:
        print(0)
    exit()
x=[len(list(v))for k,v in groupby(s)if k=="0"]
y=[len(list(v))for k,v in groupby(s)if k=="1"]
x1=array(x[:-k])
x2=array(x[k:])
x3=sum(x[:k])
t=x3+cumsum(x2-x1)
y1=array(y[:-k2])
y2=array(y[k2:])
y3=sum(y[:k2])
f=y3+cumsum(y2-y1)
print(max(max(t+f),x3+y3))

from itertools import*;from numpy import*;n,k=map(int,input().split());k=2*k+1;s=input();x=[0]*(s[0]=="0")+[len(list(v))for k,v in groupby(s)]+[0]*(s[-1]=="0");u=sum(x[:k]);print(max([u]+list(u+cumsum(array(x[k:])-array(x[:-k])))[::2]))

from numpy import*
from itertools import*
N, K = map(int, input().split())
S=input()
zeros=[len(list(v)) for k,v in groupby(S) if k=="0"]
ones =[len(list(v)) for k,v in groupby(S) if k=="1"]




c_zero= cumsum(zeros)
c_one = cumsum(ones)



if len(zeros) <= K:
    print(len(S))
else:
    ans = 0
    for i in range(0, len(zeros) - K):
        aaa = c_zero[i+K]-c_zero[i] + c_one[i+K+1]-c_one[i]
        ans = max(aaa, ans)
    print(ans)

from numpy import*
from itertools import*
N, K = map(int, input().split())
S=input()
zeros=[0]+[len(list(v)) for k,v in groupby(S) if k=="0"]
ones =[0]+(S[0]=="0")*[0]+[len(list(v)) for k,v in groupby(S) if k=="1"]+(S[-1]=="0")*[0]



c_zero= cumsum(zeros)
c_one = cumsum(ones)



if len(zeros) <= K:
    print(len(S))
else:
    ans = 0
    for i in range( len(zeros)-K ):
        aaa = c_zero[i+K]-c_zero[i] + c_one[i+K+1]-c_one[i]
        ans = max(aaa, ans)
    print(ans)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
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):
import sys
input = sys.stdin.readline 
N, K = map(int, input().split())
S = list(map(int, input()))

cnt = 0
now = 1
Nums = []

for i in range(N):
    if S[i] == now:
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now
        cnt = 1

if cnt != 0:
    Nums.append(cnt)
if len(Nums) % 2 == 0:
    Nums.append(0)

add = 2*K+1
ans = 0
left = right = 0
tmp = 0    # [left, right)

for i in range(0, len(Nums), 2):
    Nextleft = i
    Nextright = min(i+add, len(Nums))
    
    while Nextleft > left:
        tmp -= Nums[left]
        left += 1
    
    while Nextright > right:
        tmp += Nums[right]
        right += 1
    
    ans = max(tmp, ans)

print(ans)

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

cnt = 0
now = 1
Nums = []

for i in range(N):
    if S[i] == now:
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now
        cnt = 1

if cnt != 0:
    Nums.append(cnt)
if len(Nums) % 2 == 0:
    Nums.append(0)

add = 2*K+1
ans = 0
left = right = 0
tmp = 0

for i in range(0, len(Nums), 2):
    Nextleft = i
    Nextright = min(i+add, len(Nums))
    
    while Nextleft > left:
        tmp -= Nums[left]
        left += 1
    
    while Nextright > right:
        tmp += Nums[right]
        right += 1
    
    ans = max(tmp, ans)

print(ans)

Verdicts: Runtime Error

Accepted
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):
rom sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
cnt = 1
run = []
for i in range(1, len(S)):
    if S[i - 1] == S[i]:
        cnt += 1
    else:
        run.append(cnt)
        cnt = 1
    if i == len(S) - 1:
        run.append(cnt)
X = [sum(run[j: j + 2 * K + 1]) for j in range(max(len(run) - 2 * K, 1))]
if len(X) == 0:
    print(1)
else:
    print(max(X))


from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
cnt = 1
run = []
if len(S) == 1:
    run.append(1)
else:
    for i in range(1, len(S)):
        if S[i - 1] == S[i]:
            cnt += 1
        else:
            run.append(cnt)
            cnt = 1
        if i == len(S) - 1:
            run.append(cnt)
if S[0] == '0':
    run = [0] + run
if S[N - 1] == '0':
    run = run + [0]
if len(run) < 2 * K + 1:
    exit()
ans = sum(run[0: 2 * K + 1])
for j in range(2, len(run) - 2 * K):
    if j % 2 == 1:
        continue
    else:
        ans = max(ans, sum(run[j: j + 2 * K + 1]))
        print(ans)
print(ans)

from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
cnt = 1
run = []
for i in range(1, len(S)):
    if S[i - 1] == S[i]:
        cnt += 1
    else:
        run.append(cnt)
        cnt = 1
    if i == len(S) - 1:
        run.append(cnt)
X = [sum(run[j: j + 2 * K + 1]) for j in range(max(len(run) - 2 * K, 1))]
if len(X) == 0:
    print(1)
else:
    print(max(X))


from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
cnt = 1
run = []
if len(S) == 1:
    run.append(1)
else:
    for i in range(1, len(S)):
        if S[i - 1] == S[i]:
            cnt += 1
        else:
            run.append(cnt)
            cnt = 1
        if i == len(S) - 1:
            run.append(cnt)
if S[0] == '0':
    run = [0] + run
if S[N - 1] == '0':
    run = run + [0]
if len(run) < 2 * K + 1:
    print(sum(run))
    exit()
ans = sum(run[0: 2 * K + 1])
sb = ans
for j in range(2, len(run) - 2 * K):
    if j % 2 == 1:
        continue
    else:
        sb = sb - run[j - 1] - run[j - 2] + run[j + 2 * K] + run[j + 2 * K - 1]
        if sb > ans:
            ans = sb
print(ans)


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

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

people = []
prev = s[0]
neg = False
if prev == "0":
	neg = True

count = 1

for i in range(1, len(s)):
	if prev != s[i]:
		people.append(count)
		count = 0
		prev = s[i]
	count += 1
people.append(count)

print(people)

if len(people)/2 <= k:
	print(n)
	quit()


max_people, start, prep = 0, 0, 0
if neg == False:
	max_people = sum(people[:(k*2)+1])
	start = 2
	prep = max_people - people[0] - people[1]
else:
	max_people = sum(people[:k*2])
	start = 1
	prep = max_people - people[0]

scan = (k*2)+1
i = 0
for i in range(start, len(people)-(k*2)+1, 2):
	try:
		cur_sum = prep + people[i+scan-1] + people[i+scan-2]
	except IndexError:
		cur_sum = prep + people[-1]
	max_people = max(max_people, cur_sum)
	prep = cur_sum - people[i] - people[i-1]


print(max_people)



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

people = []
prev = s[0]
neg = False
if prev == "0":
	neg = True

count = 1

for i in range(1, len(s)):
	if prev != s[i]:
		people.append(count)
		count = 0
		prev = s[i]
	count += 1
people.append(count)


if len(people)/2 <= k:
	print(n)
	quit()


max_people, start, prep = 0, 0, 0
if neg == False:
	max_people = sum(people[:(k*2)+1])
	start = 2
	prep = max_people - people[0] - people[1]
else:
	max_people = sum(people[:k*2])
	start = 1
	prep = max_people - people[0]

scan = (k*2)+1
i = 0
for i in range(start, len(people)-(k*2)+1, 2):
	try:
		cur_sum = prep + people[i+scan-1] + people[i+scan-2]
	except IndexError:
		cur_sum = prep + people[-1]
	max_people = max(max_people, cur_sum)
	prep = cur_sum - people[i] - people[i+1]

print(max_people)



Verdicts: Wrong Answer

Accepted
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 = "1" + input() + "1"
arr = []
cnt = 0
flg = 1
for s in S:
    if s == "1" and 1 - flg:
        flg = 1
        arr.append(cnt)
        cnt = 1
    elif s == "0" and flg:
        flg = 0
        arr.append(cnt)
        cnt = 1
    else:
        cnt += 1
arr.append(cnt)
csum = [0] * (len(arr)+1)
for i in range(len(arr)):
    csum[i + 1] = csum[i] + arr[i]
ans = 0
for i in range(len(csum) - 2*K - 1):
    l = i
    r = i + 2*K + 1
    ans = max(ans, csum[r] - csum[l])
    ans -= (r == len(csum) - 1) + (l == 0) + (l == 1)
if len(csum) == 2:
    print(csum[1] - 2)
else:
    print(ans)


N, K = map(int, input().split())
S = "1" + input() + "1"
arr = []
cnt = 0
flg = 1
for s in S:
    if s == "1" and 1 - flg:
        flg = 1
        arr.append(cnt)
        cnt = 1
    elif s == "0" and flg:
        flg = 0
        arr.append(cnt)
        cnt = 1
    else:
        cnt += 1
arr.append(cnt)
csum = [0] * (len(arr)+1)
for i in range(len(arr)):
    csum[i + 1] = csum[i] + arr[i]
ans = 0
print(csum)
for i in range(len(csum) - 2*K - 1):
    l = i
    r = i + 2*K + 1
    ans = max(ans, csum[r] - csum[l])
    ans -= (r == len(csum) - 1) + (l == 0)
if len(csum) == 2:
    print(csum[1] - 2)
else:
    print(ans)


from itertools import accumulate
N, K = map(int, input().split())
S = "1" + input() + "1"
arr = []
cnt = 0
flg = 1
for s in S:
    if s == "1" and 1 - flg:
        flg = 1
        arr.append(cnt)
        cnt = 1
    elif s == "0" and flg:
        flg = 0
        arr.append(cnt)
        cnt = 1
    else:
        cnt += 1
arr.append(cnt)
csum = [0] + list(accumulate(arr))
ans = 0
tmp = 0
for i in range(0, len(csum), 2):
    l = i
    r = min(i + 2*K + 1, len(csum) - 1)
    tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)
    ans = max(ans, tmp)
if len(csum) == 2:
    print(csum[1] - 2)
else:
    print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
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()
last_s = "0"
count = 0
A = []
for i, s in enumerate(S):
	if i == 0:
		count += 1
	else:
		if s != last_s:
			A.append(count)
			count = 0
		count += 1
	last_s = s

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

B = []

for i in range(len(S)-(2*K+1)-1):
	B.append(sum(A[2*i:2*i+2*K+1]))

print(max(B))


N, K = map(int, input().split())
S = input()
last_s = "0"
count = 0
A = []
for i, s in enumerate(S):
	if i == 0:
		count += 1
	else:
		if s != last_s:
			A.append(count)
			count = 0
		count += 1
	last_s = s

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


val = sum(A[:2*K+1])
currentMax = val

for i in range(0, len(A)-2*K-2, 2):
	old_sum_of_two = sum(A[i:i+2])
	sum_of_two = sum(A[i+2*K+1:i+2*K+3])
	val += sum_of_two - old_sum_of_two
	if val > currentMax:
		currentMax = val

print(currentMax)


N, K = map(int, input().split())
S = input()
last_s = "0"
count = 0
A = []
for i, s in enumerate(S):
	if i == 0:
		count += 1
	else:
		if s != last_s:
			A.append(count)
			count = 0
		count += 1
	last_s = s

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

A.append(0)
A.append(0)

val = 0

if S[0] == "0":
	val = sum(A[:2*K])
	currentMax = val
	old = A[0]
	new = sum(A[2*K:2*K+2])
	val += new - old
	if val > currentMax:
		currentMax = val
	
	for i in range(1, len(A)-2*K, 2):
		old_sum_of_two = sum(A[i:i+2])
		sum_of_two = sum(A[i+2*K+1:i+2*K+3])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)
else:
	val = sum(A[:2*K+1])
	currentMax = val
	for i in range(0, len(A)-2*K, 2):
		old_sum_of_two = sum(A[i:i+2])
		sum_of_two = sum(A[i+2*K+1:i+2*K+3])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)



Verdicts: Runtime Error

Wrong Answer

Accepted
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):
import numpy as np

N, K = map(int, input().split(" "))
S = np.array([int(i) for i in input()])
pos1 = np.linspace(0,N-1,N)[S == 1]
print(pos1)
lst = []
st =[0]
for i in pos1:
    if st[-1] + 1 == i:
        st.append(i)
    else:
        lst.append(st)
        st = [i]
    if i == pos1[-1]:
        lst.append(st)
print(lst)
time = len(lst) - K
if time <= 0:
    print(N)
else:
    print(int(max([max(lst[i+K]) - min(lst[i])+1 for i in range(time)])))

import numpy as np

N, K = map(int, input().split(" "))
S = np.array([int(i) for i in input()])
pos1 = np.linspace(0,N-1,N)[S == 1]
lst = []
if len(pos1) == 0:
    print(N)
else:    
    st =[pos1[0]]
    for i in pos1[1:]:
        if st[-1] + 1 == i:
            st.append(i)
        else:
            lst.append(st)
            st = [i]
        if i == pos1[-1]:
            lst.append(st)
    lst = [[0]] + lst + [[N-1]]
    time = len(lst) - K
    if time <= 0:
        print(N)
    else:
        print(int(max([max(lst[i+K]) - min(lst[i])+1 for i in range(time)])))

import numpy as np

N, K = map(int, input().split(" "))
S = np.array([int(i) for i in input()])
pos1 = np.linspace(0,N-1,N)[S == 1]
lst = []
st =[pos1[0]]
for i in pos1[1:]:
    if st[-1] + 1 == i:
        st.append(i)
    else:
        lst.append(st)
        st = [i]
    if i == pos1[-1]:
        lst.append(st)
lst = [[0]] + lst + [[N-1]]
time = len(lst) - K
if time <= 0:
    print(N)
else:
    print(int(max([max(lst[i+K]) - min(lst[i])+1 for i in range(time)])))

import numpy as np

N, K = map(int, input().split(" "))
S = np.array([int(i) for i in input()])
pos1 = np.linspace(0,N-1,N)[S == 1]
lst = []
if len(pos1) == 0:
    print(N)
else:    
    st =[pos1[0]]
    if len(pos1) != 1:
        for i in pos1[1:]:
            if st[-1] + 1 == i:
                st.append(i)
            else:
                lst.append(st)
                st = [i]
            if i == pos1[-1]:
                lst.append(st)
    else:
        lst.append(st)
    lst = [[0]] + lst + [[N-1]]
    time = len(lst) - K
    if time <= 0:
        print(N)
    else:
        print(int(max([max(lst[i+K]) - min(lst[i])+1 for i in range(time)])))

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

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

def rle(string):
    _rle_str = string[0]
    _rle_cnt = 1
    _ans_l = []
    for _i in range(1, len(string)):
        if _rle_str == string[_i]:
            _rle_cnt += 1
        else:
            _ans_l.append([_rle_str, _rle_cnt])
            _rle_str = string[_i]
            _rle_cnt = 1
    _ans_l.append([_rle_str, _rle_cnt])
    return _ans_l

rle_s=rle(s)

ans=-1

left=0
wa=0

if rle_s[0][0]=="0":
    cnt=1
    wa=rle_s[0][1]
    right=1
else:
    cnt=0
    right=0

if len(rle_s)==1 and k>=1:
    print(rle_s[0][1])

while right<len(rle_s):
    print(right, left, wa, cnt)
    if cnt==k:
        if rle_s[right][0]=="0":
            if rle_s[left][0]=="0":
                wa-=rle_s[left][1]
                cnt-=1
            else:
                wa-=rle_s[left][1]
            left+=1

        else:
            wa+=rle_s[right][1]
            right+=1
            ans=max(ans, wa)

    elif cnt<k:
        if rle_s[right][0]=="0":
            cnt+=1
            wa+=rle_s[right][1]
        else:
            wa+=rle_s[right][1]
        right+=1
        ans=max(ans, wa)

    else:
        if rle_s[left][0]=="0":
            wa-=rle_s[left][1]
            cnt-=1
        else:
            wa-=rle_s[left][1]
        left+=1

print(ans)


def rle(string):
    _rle_str = string[0]
    _rle_cnt = 1
    _ans_l = []
    for _i in range(1, len(string)):
        if _rle_str == string[_i]:
            _rle_cnt += 1
        else:
            _ans_l.append([_rle_str, _rle_cnt])
            _rle_str = string[_i]
            _rle_cnt = 1
    _ans_l.append([_rle_str, _rle_cnt])
    return _ans_l

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

rs=rle(s)

if rs[0][0]=="0":
    cnt=1
    wa=rs[0][1]
    r=1
    l=0
else:
    cnt=0
    wa=0
    r=0
    l=0

ans=-1

if len(rs)==1:
    print(rs[0][1])
    exit()

while r<len(rs):
    if cnt==k and rs[r][0]=="0":
        if rs[l][0]=="0":
            wa-=rs[l][1]
            cnt-=1
        else:
            wa-=rs[l][1]
        l+=1

    elif cnt<=k:
        if rs[r][0]=="0":
            cnt+=1
            wa+=rs[r][1]
        else:
            wa+=rs[r][1]
        r+=1
        ans=max(ans, wa)

    else:
        if rs[l][0]=="0":
            wa-=rs[l][1]
            cnt-=1
        else:
            wa-=rs[l][1]
        l+=1

print(ans)


Verdicts: Wrong Answer

Accepted
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):
import sys,re,copy
input = sys.stdin.readline

N,K=[int(x) for x in input().strip().split()]

f=1
cnt=0
S=[]
r=0
for s in input().strip():
    s=int(s)
    if s==f:
        cnt+=1
    else:
        r+=cnt
        S.append(r)
        cnt=1
        f=1-f
else:
    r+=cnt
    S.append(r)
if len(S)%2==0:
    S.append(r)

Max=0
i=0
if len(S)==1:
    Max=S[0]
else:
    while True:
        r=i+2*K
        cnt=S[min(r,len(S)-1)]-S[max(i-1,0)]
        if cnt > Max:
            Max = cnt
        i+=2

print(Max)

import sys,re,copy
input = sys.stdin.readline

N,K=[int(x) for x in input().strip().split()]

f=1
cnt=0
S=[]
r=0
for s in input().strip():
    s=int(s)
    if s==f:
        cnt+=1
    else:
        r+=cnt
        S.append(r)
        cnt=1
        f=1-f
else:
    r+=cnt
    S.append(r)
if len(S)%2==0:
    S.append(r)

Max=0
i=0
if len(S)==1:
    Max=S[0]
else:
    while True:
        if i >=len(S):
            break
        r=i+2*K
        cnt=S[min(r,len(S)-1)]-S[max(i-1,0)]
        if cnt > Max:
            Max = cnt
        i+=2

print(Max)

Verdicts: Runtime Error

Accepted
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):
from itertools import groupby
n, k = map(int, input().split())
S = input().strip()
L = [len(list(g)) for v, g in groupby(S)]
A = [sum(L[:2*k+1])]
for i in range(0, len(L)-2*k-1, 2):
    A += A[-1]-L[i]-L[i+1]+L[i+2*k+1]+L[i+2*k+2],
print(max(A))

from itertools import groupby
n, k = map(int, input().split())
S = input().strip()
L = [len(list(g)) for v, g in groupby(S)]
if S[0] == '0':
    L = [0] + L
if S[-1] == '0':
    L = L + [0]

A = [sum(L[:2*k+1])]
for i in range(0, len(L)-2*k-1, 2):
    A += A[-1]-L[i]-L[i+1]+L[i+2*k+1]+L[i+2*k+2],
print(max(A))

Verdicts: Runtime Error

Accepted
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):
import itertools
N, K = map(int, input().split())
S = input()


human = []
humancount = []
for key, group in itertools.groupby(S):
    human.append(key)
    humancount.append(len(list(group)))

humancount
human[0]
human

humancount_ac = [0] + list(itertools.accumulate(humancount))

ans = 0
j = 0
temp = 0
count = 0

for i in range(N):
    while j <= len(human)-1:
        print(ans, i, j)
        if human[j] == "0" and count < K:
            count += 1
            j += 1
            ans = max(ans, humancount_ac[j] - humancount_ac[i])
        elif human[j] == "1":
            j += 1
            ans = max(ans, humancount_ac[j] - humancount_ac[i])
        else:
            if human[i] == "0":
                count -= 1
            break
print(ans)


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


human = []
humancount = []
for key, group in itertools.groupby(S):
    human.append(key)
    humancount.append(len(list(group)))

humancount_ac = [0] + list(itertools.accumulate(humancount))

ans = 0
j = 0
count = 0

for i in range(N):
    while j <= len(human)-1:
        if human[j] == "0" and count < K:
            count += 1
            j += 1
            ans = max(ans, humancount_ac[j] - humancount_ac[i])
        elif human[j] == "1":
            j += 1
            ans = max(ans, humancount_ac[j] - humancount_ac[i])
        else:
            if human[i] == "0":
                count -= 1
            break
print(ans)


Verdicts: Wrong Answer

Accepted
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())
head = s[0]

counts = []
_hd = head
_cnt = 0
for _s in s:
  if _s == _hd:
    _cnt += 1
  else:
    counts.append(_cnt)
    _hd = _s
    _cnt = 1
else:
  counts.append(_cnt)

acc = [0]
for c in counts:
  acc.append(acc[-1] + c)

if len(counts) <= 2*k:
  ans = len(s)
else:
  if head == '1':
    for i in range(2*k+1, len(counts)+1, 2):
      p = acc[i] - acc[i - (2*k+1)]
      ans = max(ans, p)
  else:
    for i in range(2*k, len(counts)+1, 2):
      p = acc[i] - acc[max(0, i-(2*k+1))]
      ans = max(ans, p)

print(ans)

n, k = map(int, input().split())
s = str(input())
head = s[0]

counts = []
_hd = head
_cnt = 0
for _s in s:
  if _s == _hd:
    _cnt += 1
  else:
    counts.append(_cnt)
    _hd = _s
    _cnt = 1
else:
  counts.append(_cnt)

acc = [0]
for c in counts:
  acc.append(acc[-1] + c)
if s[-1] == '0':
  acc.append(acc[-1])

ans = 1
if len(counts) <= 2*k:
  ans = len(s)
else:
  if head == '1':
    for i in range(2*k+1, len(acc)+1, 2):
      p = acc[i] - acc[i - (2*k+1)]
      ans = max(ans, p)
  else:
    for i in range(2*k, len(acc)+1, 2):
      p = acc[i] - acc[max(0, i-(2*k+1))]
      ans = max(ans, p)

print(ans)

Verdicts: Runtime Error

Accepted
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()
s = s + '#'
left = 0
right =0
l = []
while left < n:
    if s[right] == s[right+1]:
        right += 1
    else:
        l.append(right-left+1)
        right += 1
        left = right
if s[0] == '0':
    l.insert(0,0)
if s[n-1] == '0':
    l.append(0)
n = len(l)
l_sum = [0]*(n)
l_sum[0] = l[0]
for i in range(1,n):
    l_sum[i] = l[i] + l_sum[i-1]
if n <= 2*k + 1:
    print(l_sum[n-1])
else:
    res = l_sum[2*k]
    for i in range(1,n-2*k):
        res = max(res,l_sum[i+2*k]-l_sum[i-1])
    print(res)

n,k = map(int,input().split())
s = input()
s = s + '#'
left = 0
right =0
l = []
while left < n:
    if s[right] == s[right+1]:
        right += 1
    else:
        l.append(right-left+1)
        right += 1
        left = right
if s[0] == '0':
    l.insert(0,0)
if s[n-1] == '0':
    l.append(0)
n = len(l)
l_sum = [0]*(n)
l_sum[0] = l[0]
for i in range(1,n):
    l_sum[i] = l[i] + l_sum[i-1]
if n <= 2*k + 1:
    print(l_sum[n-1])
else:
    res = l_sum[2*k]
    for i in range(2,n-2*k,2):
        res = max(res,l_sum[i+2*k]-l_sum[i-1])
    print(res)

Verdicts: Wrong Answer

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

s = []
cnt = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        s.append(cnt)
        cnt = 1
s.append(cnt)

ans = 0
if S[0] == '0':
    s = [0] + s
if S[-1] == '0':
    s = s + [0]

if 2*K + 1 > len(s):
    print(sum(s))
    exit()

print(s)
for i in range(0, len(s), 2):
    if i + 2*K >= len(s):
        break
    ans = max(ans, sum(s[i:i+2*K+1]))

print(ans)

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

s = []
cnt = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        s.append(cnt)
        cnt = 1
s.append(cnt)

ans = 0
if S[0] == '0':
    s = [0] + s
if S[-1] == '0':
    s = s + [0]

if 2*K + 1 > len(s):
    print(sum(s))
    exit()

s_cumsum = [s[0]] * len(s)
for i in range(1, len(s)):
    s_cumsum[i] = s_cumsum[i-1] + s[i]
    
for i in range(0, len(s), 2):
    if i + 2*K >= len(s):
        break
    if i < 1:
        ans = s_cumsum[i+2*K]
    ans = max(ans, s_cumsum[i+2*K]-s_cumsum[i-1])
    

print(ans)

Verdicts: Wrong Answer

Accepted
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):
import numpy as np

N,K = list(map(int,input().rstrip().split()))
S = list(input())
if S[0] == '0':
    zero_start = True
else:
    zero_start = False

N_normalized = [0] if zero_start else []
tmp = '0' if zero_start else '1'
cnt = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
        if i == len(S)-1:
            N_normalized.append(cnt)
    else:
        N_normalized.append(cnt)
        cnt = 1
        tmp = S[i]
        if i == len(S)-1:
            N_normalized.append(1)
N_normalized.append(0)

ans = 0
if len(N_normalized)>K*2+1:
    for i in range(0, len(N_normalized)-(K*2), 2):
        tmp = sum(N_normalized[i:i+K*2+1])
        print(i,tmp)
        if ans < tmp:
            ans = tmp
else:
    ans = sum(N_normalized)

print(ans)

import numpy as np

N,K = list(map(int,input().rstrip().split()))
S = list(input())
if S[0] == '0':
    zero_start = True
else:
    zero_start = False

N_normalized = [0,0,0] if zero_start else [0,0]
tmp = '0' if zero_start else '1'
cnt = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
        if i == len(S)-1:
            N_normalized.append(cnt)
    else:
        N_normalized.append(cnt)
        cnt = 1
        tmp = S[i]
        if i == len(S)-1:
            N_normalized.append(1)
N_normalized.append(0)
N_normalized.append(0)
N_normalized.append(0)

tmp = sum(N_normalized[0:K*2+1])
ans = tmp

if len(N_normalized)>K*2+1:
    for i in range(2, len(N_normalized)-(K*2+1), 2):
        tmp = tmp-N_normalized[i-1]-N_normalized[i-2]+N_normalized[i+K*2-1]+N_normalized[i+K*2]
        if ans < tmp:
            ans = tmp
else:
    ans = sum(N_normalized)

print(ans)

Verdicts: Wrong Answer

Accepted
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):
import sys
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N,K = map(int, input().split())
    S = sys.stdin.readline
  else:
    # For Test
    # N = 5
    # K = 1
    # S = "00010"
    N = 14
    K = 2
    S = "11101010110011"
    # N = 1
    # K = 1
    # S = "1"
    
  SC = []
  i = 0
  if S[0] == "0":SC.append(0)
  while i < N :
    if S[i] == "0":
      j = S.find("1",i)
    else:
      j = S.find("0",i)
    if j == -1: j = N 
    cnt = j - i
    i = j
    SC.append(cnt)
    
  if 'get_ipython' in globals(): print(SC)
    
  i = 0
  lenSC = len(SC) - 1
  ans = 0
  while i <= lenSC:
    cnt = 0
    k = i + K * 2
    if k > lenSC:
      k = lenSC
    k += 1
    cnt = sum(SC[i:k])
    if ans < cnt:
      ans = cnt
    i += 2

  print(ans)

main()

import sys
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N,K = map(int, input().split())
    S = sys.stdin.readline()
  else:
    # For Test
    # N = 5
    # K = 1
    # S = "00010"
    # N = 14
    # K = 2
    # S = "11101010110011"
    # N = 1
    # K = 1
    # S = "1"
    N = 5
    K = 1
    S = "11111"
    
  SC = []
  i = 0
  if S[0] == "0":SC.append(0)
  while i < N :
    if S[i] == "0":
      j = S.find("1",i)
    else:
      j = S.find("0",i)
    if j == -1: j = N 
    cnt = j - i
    i = j
    SC.append(cnt)
    
  if 'get_ipython' in globals(): print(SC)
    
  SH = []
  cnt = 0
  for i in range(len(SC)):
    cnt += SC[i]
    SH.append(cnt)
  
  if 'get_ipython' in globals(): print(SH)
  
  lenSC = len(SC) - 1
  ans = 0
  for i in range(0,lenSC+1,2):
    k = i + K * 2
    if k > lenSC:
      k = lenSC
    if i != 0:
      cnt = SH[k] - SH[i-1]
    elif k == i:
      cnt = SH[k]
    else:
      cnt = SH[k] - SH[i]
    if ans < cnt: ans = cnt

  print(ans)

main()

Verdicts: Runtime Error

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

t = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
    s = str(i)
    t[int(s[0])][int(s[-1])] += 1

result = 0
for i in range(1, 10):
    for j in range(1, 10):
        result += t[i][j] * t[j][i]
print(result)

from itertools import accumulate
n, k = map(int, input().split())
s = [i for i in input()]
zero_one = [0]
if s[0] == "0":
    zero_one.append(0)
s_ = s[0]
cnt = 0
for i in range(n):
    if s_ == s[i]:
        cnt += 1
    else:
        zero_one.append(cnt)
        cnt = 1
        s_ = s[i]
zero_one.append(cnt)
if s[-1] == "0":
    zero_one.append(0)
ans = 0
l = len(zero_one)
zero_one = list(accumulate(zero_one))
for i in range(0, l, 2):
    ans = max(ans, zero_one[min(l-1, i+2*k+1)] - zero_one[i])
print(ans)

Verdicts: Runtime Error

Accepted
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):
from functools import reduce
from operator import add

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

current_status = "1"
s = [0]
for h in s_law:
    if h == current_status:
        s[-1] += 1
    else:
        s.append(1)
        current_status = h

join_num = k * 2 + 1

max_rev = 0
for i, state in enumerate(s):
    max_rev = max(reduce(add, s[i:i + join_num]), max_rev)

print(max_rev)


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

h = (0, S[0])
t = (0, S[0])
k = 1 if S[0] == '0' else 0
max_handstands = 1
current_handstands = 1
while True:
    if h[0] == N-1 and t[0] == N-1:
        break
    
    elif t[0] < N-1 and not (t[1] == '1' and S[t[0]+1] == '0'):
        t = (t[0]+1, S[t[0]+1])
        current_handstands += 1
    
    elif t[0] < N-1 and k < K and S[t[0]+1] != t[1]:
        k += 1
        t = (t[0]+1, S[t[0]+1])
        current_handstands += 1
    
    elif not (h[1] == '0' and S[h[0]+1] == '1') and h[0] < t[0]:
        max_handstands = max(max_handstands, current_handstands)
        h = (h[0]+1, S[h[0]+1])
        current_handstands -= 1
    
    elif S[h[0]+1] != h[1] and h[0] < t[0]:
        max_handstands = max(max_handstands, current_handstands)
        k -= 1
        h = (h[0]+1, S[h[0]+1])
        current_handstands -= 1
    else:
        raise

print(max_handstands)


Verdicts: Wrong Answer

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

a = [0]
tmp = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        a.append(tmp)
        tmp += 1
a.append(tmp)
m = len(a)
ans = 1
if len(a) == 2 or m-2*k < 1:
    ans = a[m-1]
elif s[0] == "1":
    for i in range(1,m-2*k):
        if i % 2 != 0:        
            ans = max(ans,a[2*k+i]-a[i-1])
        elif 2*k+i == m - 1:
            ans = max(ans,a[m-1]-a[i-1])
        else:
            ans = max(ans,a[2*k+i-1]-a[i-1])
else:
    for i in range(1,m-2*k):
        if i % 2 == 0:        
            ans = max(ans,a[2*k+i]-a[i-1])
        elif 2*k+i == m - 1:
            ans = max(ans,a[m-1]-a[i-1])
        else:
            ans = max(ans,a[2*k+i-1]-a[i-1])
print(ans)


n,k = map(int,input().split(" "))
s = list(input())
a = [1]
for i in range(1,n):
    if s[i] != s[i-1]:
        a.append(i+1)
m = len(a)
ans = 1
i = 1
for i in range(m):
    if s[a[i]-1] == "1":
        if 2*k + i +1 < m:        
            ans = max(ans,a[2*k+i+1]-a[i])
        else:
            ans = max(ans,n+1- a[i])
    else:
        if 2*k+i< m:        
            ans = max(ans,a[2*k+i]-a[i])
        else:
            ans = max(ans,n+1-a[i])
print(ans)


Verdicts: Wrong Answer

Accepted