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

offset = not (int(S[0]) ^ (K & 1))
runs = []

prev = S[0]
run = 0
for c in S:
    if c != prev:
        runs.append(run)
        run = 0
    prev = c
    run += 1
runs.append(run)

L = len(runs)
candidates = []

prev = sum(runs[max(0, offset - K): min(L, offset + K + 1)])
answer = prev

for i in range(offset + 2, L, 2):
    now = prev
    old_left = i - 2 - K
    new_right = i + K
    if old_left >= 0:
        now -= runs[old_left]
    if old_left + 1 >= 0:
        now -= runs[old_left + 1]
    if new_right - 1 < L:
        now += runs[new_right - 1]
    if new_right < L:
        now += runs[new_right]
    prev = now
    if answer > prev:
        answer = prev

print(answer)

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

offset = not (int(S[0]) ^ (K & 1))
runs = []

prev = S[0]
run = 0
for c in S:
    if c != prev:
        runs.append(run)
        run = 0
    prev = c
    run += 1
runs.append(run)

L = len(runs)
candidates = []

prev = sum(runs[max(0, offset - K): min(L, offset + K + 1)])
answer = prev

for i in range(offset + 2, L, 2):
    now = prev
    old_left = i - 2 - K
    new_right = i + K
    if old_left >= 0:
        now -= runs[old_left]
    if old_left + 1 >= 0:
        now -= runs[old_left + 1]
    if new_right - 1 < L:
        now += runs[new_right - 1]
    if new_right < L:
        now += runs[new_right]
    prev = now
    if prev > answer:
        answer = prev

print(answer)


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()
l = r = 0
a = []
while l < n:
    while r < n and s[l] == s[r]:
        r += 1
    a.append(r-l)
    l = r
m = len(a)
asum = [0 for _ in range(m+1)]
ans = 0
for i in range(m):
    asum[i+1] = asum[i] + a[i]
if s[0] == '0':
    if k >= m//2:
        ans = n
    else:
        if s[-1] == '0':
            a.append(0)
            asum.append(asum[-1])
        for i in range(1, m-2*k):
            if i % 2 == 0:
                continue
            ans = max(ans, asum[2*k+i+1] - asum[i])
        ans = max(ans, asum[2*k])
else:
    if k >= m//2:
        ans = n
    else:
        if s[-1] == '0':
            a.append(0)
            asum.append(asum[-1])
        for i in range(0, m-2*k):
            if i % 2 == 1:
                continue
            ans = max(ans, asum[2*k+i+1] - asum[i])
print(ans)

n, k = map(int, input().split())
s = input()
a = []
if s[0] == '0':
    a.append(0)
l = r = 0
while l < n:
    while r < n and s[l] == s[r]:
        r += 1
    a.append(r-l)
    l = r
if s[-1] == '0':
    a.append(0)
m = len(a)
if m // 2 <= k:
    print(n)
else:
    ans = 0
    asum = [0 for _ in range(m+1)]
    for i in range(m):
        asum[i+1] = asum[i] + a[i]
    for i in range(m+1-2*k):
        if i % 2:
            continue
        ans = max(ans, asum[i+2*k+1] - asum[i])
    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
N,K = map(int,input().split())
S = input()

li_s = []
count = 1
temp = S[0]
if temp == "0":
    li_s.append(0)
for i in range(1,N):
    if S[i] != temp:
        if i == N-1:
            li_s.append(count)
            li_s.append(1)
        else:
            li_s.append(count)
            temp = S[i]
            count = 1
    elif i == N-1:
        count += 1
        li_s.append(count)
    else:
        count += 1

for i in range(100000):
    li_s.append(0)
max = 0

if K == 1:
    print(1)
    sys.exit()
for i in range(N - K*2+1):
    temp = 0
    if i % 2 == 0:
        for j in range(i,i+K*2+1):
            temp += li_s[j]
    else:
        for j in range(i,i+K*2):
            temp += li_s[j]

    if temp > max:
        max = temp
print(max)



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

li_s = []
count = 1
temp = S[0]
if temp == "0":
    li_s.append(0)
for i in range(1,N):
    if S[i] != temp:
        if i == N-1:
            li_s.append(count)
            li_s.append(1)
        else:
            li_s.append(count)
            temp = S[i]
            count = 1
    elif i == N-1:
        count += 1
        li_s.append(count)
    else:
        count += 1

for i in range(100000):
    li_s.append(0)
max = 0

if K == 1:
    print(1)
for i in range(N - K*2+1):
    temp = 0
    if i % 2 == 0:
        for j in range(i,i+K*2+1):
            temp += li_s[j]
    else:
        for j in range(i,i+K*2):
            temp += li_s[j]

    if temp > max:
        max = temp
print(max)



n,k = map(int,input().split())
s = input()
tmp = s[0]
cnt = 1
ss = []
if s[0] == '0':
    ss.append(0)

for i in range(1,n):
    if s[i] == tmp:
        cnt += 1
    else:
        tmp = s[i]
        ss.append(cnt)
        cnt = 1
ss.append(cnt)
if s[-1] == '0':
    ss.append(0)
ll = len(ss)

l = 0
r = k*2
tt = sum(ss[l:r+1])
ans = tt
while True:
    l += 2
    r += 2
    if r > ll:
        break
    tt += ss[r] + ss[r-1]
    tt -= ss[l-1] + ss[l-2]
    ans = max(ans, tt)
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 = map(int, input())

now = 1
cnt = 0
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
tmp_sum = 0

left = 0
right = 0

ans = 0

for i in range(0, n, 2):

    next_right = i
    next_left = min(i + add, n)

    while left < next_left:
        tmp_sum -= nums[left]
        left++

    while right < next_right:
        tmp_sum += nums[right]
        right++

    ans = max(tmp_sum, ans)

print(ans)


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

now = 1
cnt = 0
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
tmp_sum = 0

left = 0
right = 0

ans = 0

for i in range(0, len(nums), 2):

    next_left = i
    next_right = min(i + add, len(nums))

    while left < next_left:
        tmp_sum -= nums[left]
        left+=1

    while right < next_right:
        tmp_sum += nums[right]
        right+=1

    ans = max(tmp_sum, 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):
# D
n, k = map(int, input().split())
s = str(input())
r = 0
l = 0
max_len = 0
count = k
ans = 0
if all([int(i) == 1 for i in list(s)]):
    ans = len(s)
else:
    while r < n:
        if r == n-1:
            break
        while count > 0:
            if r == n-1:
                break
            if int(s[r]) == 1:
                r += 1
                continue
            else:
                count -= 1
                while int(s[r]) == 0:
                    if r == n-1:
                        break
                    r += 1
                while int(s[r]) == 1:
                    if r == n-1:
                        break
                    if r == n-2 and int(s[n-1]) == 0:
                        break
                    if int(s[r+1]) == 0:
                        break
                    r += 1
                continue
        print(l,r)
        ans = max(ans, r - l + 1)
        while int(s[l]) == 1:
            if l == n-1:
                break
            l += 1
        while int(s[l]) == 0:
            if l == n-1:
                break
            l += 1
        count += 1
print(ans)

# D
n, k = map(int, input().split())
s = str(input())
r = 0
l = 0
max_len = 0
count = k
ans = 0
if all([int(i) == 1 for i in list(s)]):
    ans = len(s)
else:
    while r < n:
        if r == n-1:
            break
        while count > 0:
            if r == n-1:
                break
            if int(s[r]) == 1:
                r += 1
                continue
            else:
                count -= 1
                while int(s[r]) == 0:
                    if r == n-1:
                        break
                    r += 1
                while int(s[r]) == 1:
                    if r == n-1:
                        break
                    if r == n-2 and int(s[n-1]) == 0:
                        break
                    if int(s[r+1]) == 0:
                        break
                    r += 1
                continue
        ans = max(ans, r - l + 1)
        while int(s[l]) == 1:
            if l == n-1:
                break
            l += 1
        while int(s[l]) == 0:
            if l == n-1:
                break
            l += 1
        count += 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):


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

ones = []
t = 0
for i in range(N):
    if i == 0:
        t += 1
        pass
    elif (S[i - 1] != S[i]):
        ones.append(t)
        t = 1
    else:
        t += 1
ones.append(t)

if S[0] == '0':
    t = ones
    ones = [0]
    ones.extend(t)

ones1 = []
for k in range(0, len(ones), 2):
    temp_k = 0
    if k < len(ones):
        temp_k += ones[k]
    if (k + 1) < len(ones):
        temp_k += ones[k + 1]
    if (k + 2) < len(ones):
        temp_k += ones[k + 2]
    ones1.append(temp_k)


f = True
res = 0
for k in range(K):
    if k >= len(ones1):
        print(res)
        f = False
        break
    res += ones1[k]

temp = 0
if f:
    for k in range(k, len(ones1), 2):

        temp_k = 0
        if k < len(ones):
            temp_k += ones[k] - 1
        if (k + 1) < len(ones):
            temp_k += ones[k + 1] - 1

        temp_res = res - temp + temp_k
        temp = temp_k
        if res < temp_res:
            res = temp_res

    print(res)


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

ones = []
t = 0
for i in range(N):
    if i == 0:
        t += 1
        pass
    elif (S[i - 1] != S[i]):
        ones.append(t)
        t = 1
    else:
        t += 1
ones.append(t)

if S[0] == '0':
    t = ones
    ones = [0]
    ones.extend(t)

res = 0
if len(ones) >= (2 * K + 1):
    for k in range(2 * K + 1):
        res += ones[k]
else:
    print(sum(ones))
    res = -1

ans = res
if res >= 0:
    for i in range(2 * K + 1, len(ones), 2):
        res += ones[i]
        if i + 1 < len(ones):
            res += ones[i + 1]

        res -= ones[i - 2 * K] + ones[i - 2 * K - 1]
        if ans < res:
            ans = res
    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
N, K = map(int, input().split())
s = input()
  
group = []
sign = s[0]
curr = 0
for i in range(N):
  curr += 1
  if s[i] != sign: 
    group += [curr-1]
    curr = 1
    sign = s[i]
else:group += [curr]

if s[0] == '0' :
  if s[N-1] == '0':
    m = (len(group)+1)//2
    if K >= m:
      print(N)
      sys.exit()
    score = [sum(group[:2*K])]
    for i in range(m-K):
      score += [score[-1] - group[2*i]  - group[2*i+1] + group[2*i+2*K+1]+group[2*i+2*K]]
  else :
    m = (len(group)+1)//2
    if K >= m:
      print(N)
      sys.exit()
    score = [sum(group[:2*K])]
    for i in range(m-K):
      score += [score[-1] - group[2*i] - group[2*i+1] + group[2*i+2*K+1]+group[2*i+2*K]]
    score[-1] += group[-1]
else:
  m = len(group)//2
  group += [0]
  if K >= m:
    print(N)
    sys.exit()
  score = [sum(group[:2*K+1])]
  for i in range(m-K):
    score += [score[-1] - group[2*i] - group[2*i+1] + group[2*i+2*K+1]+group[2*i+2*K +2]]

print(max(score))

N, K = map(int, input().split())
s = input()
  
group = []
if s[0] == '0' :
  group = [0]
sign = s[0]
curr = 0
for i in range(N):
  curr += 1
  if s[i] != sign: 
    group += [curr-1]
    curr = 1
    sign = s[i]
else:group += [curr]
if s[-1] == '0':
  group += [0]

m = len(group)//2
if K >= m:
  print(N)
else:
  score = [sum(group[:2*K+1])]
  for i in range(m-K):
    score += [score[-1] - group[2*i]  - group[2*i+1] + group[2*i+2*K+1]+group[2*i+2*K+2]]
  
  print(max(score))

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

array = [0]
result = 0
if S[0] == '1':
    flag = False

else:
    flag = True

flag2 = False

for i in range(N):
    if S[i] == '0':
        if not flag:
            flag = True
            array.append(i)
            if len(array) == K * 2 + 2:
                flag2 = True
                result = max(array[-1] - array[0], result)
                del array[0]
                del array[0]
            

    else:
        if flag:
            flag = False
            array.append(i)

result = max(N - array[0], result)

print(result if flag2 else N)


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

array = [0]
result = 0
if S[0] == '1':
    flag = False

else:
    flag = True
    array.append(0)

flag2 = False

for i in range(N):
    if S[i] == '0':
        if not flag:
            flag = True
            array.append(i)
            if len(array) == K * 2 + 2:
                flag2 = True
                result = max(array[-1] - array[0], result)
                del array[0]
                del array[0]
            

    else:
        if flag:
            flag = False
            array.append(i)

result = max(N - array[0], result)

print(result if flag2 else N)


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

judge=[0]
max_=0
for i in range(n-1):
  if s[i]!=s[i+1]:
    judge.append(i+1)
judge.append(n)

if len(judge)//2<=k:
  print(len(s))
else:
  for i in range(len(judge)-2*k):
    if s[judge[i]]=='0':
      ans=judge[i+2*k]-judge[i]
    else:
      ans=judge[i+2*k+1]-judge[i]
    if ans>max_:
      max_=ans
  print(max_)

n,k=map(int, input().split())
c=list(input())
place=[-1]
dist=[0]*n
for i in range(len(c)-1):
    if c[i]!=c[i+1]:
        place.append(i)
place.append(n-1)
for i in range(len(place)-2*k-2):
    dist[i]=place[i+2*k+2]-place[i]
print(max(max((dist))-1),n)

n,k=map(int, input().split())
c=list(input())
place=[0]
dist=[0]*n
for i in range(len(c)-1):
    if c[i]!=c[i+1]:
        place.append(i)
place.append(n-1)
for i in range(len(place)-2*k-2):
    dist[i]=place[i+2*k+2]-place[i]
print(max(dist)-1)

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

judge=[0]
max_=0
for i in range(n-1):
  if s[i]!=s[i+1]:
    judge.append(i+1)
judge.append(n)

if len(judge)//2<=k:
  print(len(s))
else:
  for i in range(len(judge)-1):
    if s[judge[i]]=='0':
      ans=judge[min(i+2*k,len(judge)-1)]-judge[i]
    else:
      ans=judge[min(i+2*k+1,len(judge)-1)]-judge[i]
    if ans>max_:
      max_=ans
  print(max_)

Verdicts: Runtime Error

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):
N, K = map(int, input().split())
S = input().replace('\n', '')


def solve(S, K):
    record = []
    temp = []
    for i in range(len(S) - 1):
        if S[i:i+2] == '01':
            temp.append(i + 1)
        elif S[i:i+2] == '10':
            if not temp: temp = [0, i]
            else: temp.append(i)
            record.append(temp)
            temp = []
    if len(temp) > 0:
        temp.append(len(S) - 1)
        record.append(temp)
    if S[0] == '0':
        record = [[0, record[0][0] - 1]] + record
    if S[-1] == '0':
        record = record + [[record[-1][-1] + 1, len(S) - 1]]
    print(record)
    if len(record) <= K + 1: return(len(S))
    else:
        cnt = 0
        for i in range(len(record) - K):
            cnt = max(cnt, record[i + K][1] - record[i][0] + 1)
        return(cnt)
print(solve(S, K))

N, K = map(int, input().split())
S = input().replace('\n', '')


def solve(S, K):
    record = []
    temp = []
    for i in range(len(S) - 1):
        if S[i:i+2] == '01':
            temp.append(i + 1)
        elif S[i:i+2] == '10':
            if not temp: temp = [0, i]
            else: temp.append(i)
            record.append(temp)
            temp = []
    if len(temp) > 0:
        temp.append(len(S) - 1)
        record.append(temp)
    if S[0] == '0':
        record = [[0, 0]] + record
    if S[-1] == '0':
        record = record + [[len(S) - 1, len(S) - 1]]
    if len(record) <= K + 1: return(len(S))
    else:
        cnt = 0
        for i in range(len(record) - K):
            cnt = max(cnt, record[i + K][1] - record[i][0] + 1)
        return(cnt)
print(solve(S, K))

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()
numbers = [len(c) for c in s.replace('0',' ').split()]
zero = [len(c) for c in s.replace('1',' ').split()]
ans = 0
if len(numbers) == 1:
    ans = numbers[0]
else:
    if len(zero) <= k:
        ans = sum(numbers) + sum(zero)
    else:
        for i in range(len(zero)-k+1):
            total = sum(zero[i:i+k]) + sum(numbers[i:i+k+1])
            ans = max(ans,total)
print(ans)

n,k = map(int,input().split())
s = input()
numbers = [len(c) for c in s.replace('0',' ').split()]
zero = [len(c) for c in s.replace('1',' ').split()]
ans = 0
if len(numbers) == 1:
    ans = numbers[0]
else:
    for i in range(len(zero)-k+1):
        total = sum(zero[i:i+k]) + sum(numbers[i:i+k+1])
        ans = max(ans,total)
print(ans)


n,k = map(int,input().split())
S = input()
nums = []
now = 1
cnt = 0
for i in range(n):
    if S[i] == str(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
l = 0
r = 0
tmp = 0

for i in range(0,len(nums),2):
    nl = i
    nr = min(i+add,len(nums))
    
    while nl > l:
        tmp -= nums[l]
        l += 1
    while nr > r:
        tmp += nums[r]
        r += 1
    ans = max(tmp,ans)

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 = []
count = 0
last = 1
for i in input():
    if i=='1':
        if last==1:
            count+=1
        else:
            s.append(count)
            count=1
        last = 1
    else:
        if last==0:
            count+=1
        else:
            s.append(count)
            count=1
        last = 0
s.append(count)
if last=='0':
    s.append(0)

k = min(k,len(s)//2)
ans = 0

for j in range(len(s)//2-k+1):
    if j==0:
        now = sum(s[:k*2+1])
        ans = now
    else:
        now = now-s[j*2-1]-s[j*2-2]+s[(j+k)*2]+s[(j+k)*2-1]
        ans = max(ans,now) 
print(ans)

#ABC124 D-Handstand
n,k = map(int,input().split())
s = []
count = 0
last = 1
for i in input():
    if i=='1':
        if last==1:
            count+=1
        else:
            s.append(count)
            count=1
        last = 1
    else:
        if last==0:
            count+=1
        else:
            s.append(count)
            count=1
        last = 0
s.append(count)
if last==0:
    s.append(0)

k = min(k,len(s)//2)
ans = 0

for j in range(len(s)//2-k+1):
    if j==0:
        now = sum(s[:k*2+1])
        ans = now
    else:
        now = now-s[j*2-1]-s[j*2-2]+s[(j+k)*2]+s[(j+k)*2-1]
        ans = max(ans,now) 
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()
cnt = 1
counts = []

if S[0]=='0':
  counts.append(0)
if N == 1:
  counts.append(1)
  
for i in range(1,N):
  if S[i-1]!=S[i]:
    counts.append(cnt)
    cnt = 1
  else:
    cnt += 1
  print(i)
  if i == N-1:
    counts.append(cnt)

print(counts)
m = 0
K = min(K,len(counts)//2)
for i in range(len(counts)//2-K+1):
  m = max(m,sum(counts[2*i:2*(i+K)+1]))
print(m)

N, K = map(int, input().split())
S = input()
cnt = 1
counts = []

if S[0]=='0':
  counts.append(0)
if N == 1:
  counts.append(1)
  
for i in range(1,N):
  if S[i-1]!=S[i]:
    counts.append(cnt)
    cnt = 1
  else:
    cnt += 1
  #print(i)
  if i == N-1:
    counts.append(cnt)

#print(counts)
K = min(K,len(counts)//2)
for i in range(len(counts)//2-K+1):
  if i == 0:
    s = sum(counts[:2*K+1])
    m = s
  else:
    s += sum(counts[2*(i+K)-1:2*(i+K)+1])-sum(counts[2*i-2:2*i])
    m = max(m,s)
  #print(s)
print(m)


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

Nums = [] 
now = 1 
cnt = 0 

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

if cnt != 0:
  Nums.append(cnt)



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

Add = 2 * K + 1

# 0 1 2 3 4 5 6
#  0 1 2 3 4 5
sum = [0] * (len(Nums) + 1)
for i in range(len(Nums)):
    sum[i + 1] = sum[i] + Nums[i]

print(Nums ,sum)
ans = 0

for i in range(0, len(Nums), 2):
    print(i, sum[i])
    
    left = i
    right = min(i + Add, len(Nums))
    tmp = sum[right] - sum[left]
    ans = max(tmp, ans)

print(ans)

from itertools import accumulate
from operator import add
N, K = map(int, input().split())
S = input()

Nums = []

tmp = "1"
cnt = 0
for s in S:
  if s == tmp:
    cnt += 1
  else:
    Nums.append(cnt)
    tmp = s
    cnt = 1
else:
  Nums.append(cnt)
  if tmp == "0":
    Nums.append(0)

T = list(accumulate(Nums))
T.insert(0,0)

ans = 0
len_t = len(T)
for i in range(0, len_t, 2):
  left = i
  right = min(len_t - 1, (2 * K + 1) + i)
  ans = max(ans, T[right] - T[left])

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

ans = 0
for i in range(n):
    if i != 0 and s[i-1] == '1':
        continue
    if i != 0 and s[i] == '0' and s[i-1] == '0':
        continue
    inv_count = 0
    continuous_count = 0
    for j in range(i, n):
        if i == 0 and s[0] == '0':
            inv_count += 1
        elif s[j-1] != '0' and s[j] == '0':
            inv_count += 1
        if inv_count > k:
            break
        continuous_count += 1
    ans = max(ans, continuous_count)
print(ans)


n, k = map(int, input().split())
s = input()
b = [1]
if s[0] == "0":
    b = [0, 1]
for i in range(1, n):
    if s[i-1] != s[i]:
        b += [1]
    else:
        b[-1] += 1
if s[-1] == "0":
    b += [0]
if len(b)//2 <= k:
    print(n)
    exit()

x = a = sum(b[:k*2+1])
for i in range(k, len(b)//2):
    a += b[i*2+1]+b[(i+1)*2]
    a -= b[(i-k)*2]+b[(i-k)*2+1]
    x = max(a, x)
print(x)


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()+"2"
L = []
cnt = 0
temp = int(S[0])

for x in S:
  if temp == int(x):
    cnt += 1
  else:
    L.append(cnt)
    cnt = 1
    temp = int(x)

if S[0] == "0":
  Lcs = [0, 0]
else:
  Lcs = [0]

for x in L:
  Lcs.append(Lcs[-1] + x)
 
ans = Lcs[1]
N = len(Lcs)
i = 2

while i + 2*(K-1) <= N-1:
  if i + 2*(K-1) == N-1:
    ans = max(ans, Lcs[i + 2*(K-1)]-Lcs[i-2])
  else:
    ans = max(ans, Lcs[i + 2*(K-1) +1]-Lcs[i-2])
    print(ans)
  i += 2

print(ans)

N, K = map(int, input().split())
S = input()+"2"
L = []
cnt = 0
temp = int(S[0])

for x in S:
  if temp == int(x):
    cnt += 1
  else:
    L.append(cnt)
    cnt = 1
    temp = int(x)

if S[0] == "0":
  Lcs = [0, 0]
else:
  Lcs = [0]

for x in L:
  Lcs.append(Lcs[-1] + x)
 
ans = Lcs[1]
N = len(Lcs)
i = 2

if i + 2*(K-1) > N-1:
  print(Lcs[-1])
else:
  while i + 2*(K-1) <= N-1:
    if i + 2*(K-1) == N-1:
      ans = max(ans, Lcs[i + 2*(K-1)]-Lcs[i-2])
    else:
      ans = max(ans, Lcs[i + 2*(K-1) +1]-Lcs[i-2])
    i += 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):
n, k = map(int, input().split())
s = input()
c = 1
l = []
l += [0,0] if (s[0] == '0') else [0]
for i in range(1, n):
    if s[i-1] != s[i]: l += [c+l[-1]]; c = 1; else: c +=1
l += [c+l[-1]]
if s[-1] == '0': l += [l[-1]]
ll = len(l)
pl = 2 * k + 1
if ll <= pl: print(n)
else: m = 0
   for i in range(0, ll-pl+1, 2): t = l[pl+i]-l[i]; m = t if (t > m) else m
   print(m)
  

n, k = map(int, input().split())
s = input()
c = 1
l = []

l += [0,0] if (s[0] == '0') else [0]

for i in range(1, n):
    if s[i-1] != s[i]:
        l += [c+l[-1]]
        c = 1
    else: 
        c +=1
l += [c+l[-1]]

if s[-1] == '0':
    l += [l[-1]]

ll = len(l)
pl = 2 * k + 1

print(l)
print(ll, pl)

if ll <= pl:
    print(n)
else:
   m = 0
   for i in range(0, ll-pl+1, 2):
       t = l[pl+i]-l[i]
       m = t if (t > m) else m
   print(m)
  

n, k = map(int, input().split())
s = input()
l = [0,0] if (s[0] == '0') else [0]
l += [i for i in range(1,n) if s[i-1] != s[i]]
l += [n] if (s[-1] == '1') else [n,n]

ll = len(l)
pl = 2 * k + 1
if (ll < pl):
    print(n)
else:
   print(max(l[pl+i]-l[i] for i in range(0, ll-pl+1, 2)))


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
import sys

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

State = [0] * N
counter0 = 0
counter1 = 0
flag = -1
jj = 0
for i in range(N):
    if S[i] == '0':
        if flag == 1:
            State[jj] = counter1
            jj +=1
            counter1 = 0
        counter0 += 1
        flag = 0
    if S[i] == '1':
        if flag == 0:
            State[jj] = counter0
            jj += 1
            counter0 = 0
        counter1 += 1
        flag = 1
    if i == N-1:
        State[jj] = max(counter0,counter1)
        
N2 = np.count_nonzero(State)
State = State[:N2]
ans = 0
K2 = 2*K+1
if K2 >= N2:
    K2 = N2        
    for i in range(K2):
        ans += State[i]
    print(ans)
    sys.exit()

for i in range(K2):
    ans += State[i]
    
for i in range(N2-K2):
    ans2 = ans - State[i]
    ans2 += State[i+K2]
    ans3 = max(ans,ans2)
    ans = ans2
    
print(ans3)

import numpy as np

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

State = [0] * N
counter0 = 0
counter1 = 0
flag = -1
jj = 0
for i in range(N):
    if S[i] == '0':
        if flag == 1:
            State[jj] = counter1
            jj +=1
            counter1 = 0
        counter0 += 1
        flag = 0
    if S[i] == '1':
        if flag == 0:
            State[jj] = counter0
            jj += 1
            counter0 = 0
        counter1 += 1
        flag = 1
    if i == N-1:
        State[jj] = max(counter0,counter1)
        
N2 = np.count_nonzero(State)
State = int(S[0] == '0') * [0] + State[:N2] + int(S[N-1] == '0') * [0]
N2 = len(State)
ans = 0
total = 0
K2 = 2*K+1

if K2 >= N2:
    K2 = N2

for i in range(K2):
    total += State[i]
        
ans = total
for i in range(0,N2-K2,2):
    total2 = total - State[i] - State[i+1] + State[i+K2] + State[i+1+K2]
    ans = max(ans,total2)
    total = total2
    
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 = input()
memo = []
c = 0
ps = ''
lens = len(s) - 1
b = 0
if s[0] == '1':
    b = 1

for i in range(lens + 1):
    if s[i] != ps:
        memo.append(c)
        c = 1
        ps = s[i]
        if i == lens:
            memo.append(1)
        continue
    if i == lens:
        memo.append(c+1)
    c += 1
    ps = s[i]
sum = 0
if  len(memo) < k * 2 + b + 1:
    print(sum(memo))
    else:
    sum = sum(memo[: k * 2 + b + 1])
    temp = [sum]
    memo.append(0)
    # print(memo)
    # print(len(memo))
    for i in range(0, len(memo) - 2 * k  - 1, 2):
        sum = sum - memo[i] - memo[i + 1] + memo[i + 2 * k  + 1] + memo[i + 2 * k + 2]
        temp.append(sum)
    # print(temp)
    print(max(temp))


n, k = map(int, input().split())
s = input()
memo = []
c = 0
ps = ''
lens = len(s) - 1
b = 0
if s[0] == '1':
    b = 1

for i in range(lens + 1):
    if s[i] != ps:
        memo.append(c)
        c = 1
        ps = s[i]
        if i == lens:
            memo.append(1)
        continue
    if i == lens:
        memo.append(c+1)
    c += 1
    ps = s[i]
sum = 0
if  len(memo) < k * 2 + b + 1:
    print(sum(memo))
else:
    sum = sum(memo[: k * 2 + b + 1])
    temp = [sum]
    memo.append(0)
    # print(memo)
    # print(len(memo))
    for i in range(0, len(memo) - 2 * k  - 1, 2):
        sum = sum - memo[i] - memo[i + 1] + memo[i + 2 * k  + 1] + memo[i + 2 * k + 2]
        temp.append(sum)
    # print(temp)
    print(max(temp))


n, k = map(int, input().split())
s = input()
memo = []
c = 0
ps = ''
lens = len(s) - 1
b = 0
if s[0] == '1':
    b = 1

for i in range(lens + 1):
    if s[i] != ps:
        memo.append(c)
        c = 1
        ps = s[i]
        if i == lens:
            memo.append(1)
        continue
    if i == lens:
        memo.append(c+1)
    c += 1
    ps = s[i]

if  len(memo) < k * 2 + b + 1:
    print(sum(memo))
else:
    sumi = 0
    sumi = sum(memo[: k * 2 + b + 1])
    temp = [sumi]
    memo.append(0)
    # print(memo)
    # print(len(memo))
    for i in range(b, len(memo) - 2 * k  - 1, 2):
        last = 0
        if i + 2 * k + 2 <= len(memo) - 1:
            last = memo[i + 2 * k + 2]
        sumi = sumi - memo[i] - memo[i + 1] + memo[i + 2 * k  + 1] +last
        temp.append(sumi)
    # print(temp)
    print(max(temp))


Verdicts: Runtime Error

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()
g=[]
t=1
for i in range(1,n):
 if s[i]==s[i-1]:t+=1
 else:g.append(t);t=1
g.append(t)
for i in range(1,len(g)):g[i]+=g[i-1]
g=[0]+g+[g[-1]]
print(max(g[i]-g[max(0,i-2*k-1)]for i in range(s[0]=='1',len(g),2))

n,k=map(int,input().split())
s='1'+input()
i=j=0
while j<n:k-='10'==s[j:j+2];i+=k<0;k+=k<0and'01'==s[i:i+2];j+=1
print(n-i)

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 math
 
N,K = (int(x) for x in input().split())
S = input()
 
list1 = []
now = 1
count = 0
 
for i in range(N):
    if now == int(S[i]):
        count += 1
    else:
        list1.append(count)
        now = 1-now
        count = 1
else:
    list1.append(count)

if len(list1) % 2 == 0:
    list1.append(0) 
tmp=0
left=0
right=0
ans=0
for i in range(0,len(list1),2):
    nextleft = i
    while left<nextleft:
        tmp = tmp - list1[left]
        left = left + 1

nextright = min(i+2*K+1,len(list1))
while right<nextright:
    tmp = tmp + list1[right]
    right = right + 1

ans=max(ans,tmp)print(ans)

print(ans)

import math
 
N,K = (int(x) for x in input().split())
S = input()
 
list1 = []
now = 1
count = 0
 
for i in range(N):
    if now == int(S[i]):
        count += 1
    else:
        list1.append(count)
        now = 1-now
        count = 1
else:
    list1.append(count)

if len(list1) % 2 == 0:
    list1.append(0)
 
tmp=0
left=0
right=0
ans=0
for i in range(0,len(list1),2):
    nextleft = i
    while left<nextleft:
        tmp = tmp - list1[left]
        left = left + 1
 
    nextright = min(i+2*K+1,len(list1))
    while right<nextright:
        tmp = tmp + list1[right]
        right = right + 1

    ans=max(ans,tmp)

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 = list(map(int,input()))
s_list = list()
num = s[0]
temp_streak = 0
temp_max = 0
[s_list.append(0) for i in range(1+s[0])]

for i in s:
    if i == num:
        temp_streak += 1
    else:
        s_list.append(temp_streak)
        temp_streak = 1
        num = i
s_list.append(temp_streak)
[s_list.append(0) for i in range(1+s[-1])]

num_i = len(s_list) // 2 
print(s_list)

for i in range(max(num_i+1-k,1)):
    temp_max = max(temp_max,sum(s_list[i*2:i*2+k*2+1]))
print(temp_max)




#print(s_list)

n,k = map(int,input().split())
s = input()
ms = 0
ps = 0
temp = [0]
if s[0] == "0":
    temp.append(0)
for i in s:
    # print(i,ps,ms)
    if i == "0":
        ms += 1
        if ps:
            temp.append(ps)
            ps = 0
    else:
        ps += 1
        if ms:
            temp.append(ms)
            ms = 0
if ms:
    temp.append(ms)
else:
    temp.append(ps)
# print(temp)
temp.append(0)
for i in range(len(temp)-1):
    temp[i+1] += temp[i]
# print(temp)
ans = 0
if len(temp)-(2*k+1) <= 0:
    ans = temp[-1]
else:
    for i in range(0,len(temp)-(2*k+1),2):
        ans = max(ans,temp[i+2*k+1]-temp[i])
print(ans)

Verdicts: Wrong Answer

Accepted