AtCoder Beginner Contest 124
D
Handstand
AtCoder
⌀ 1138
原题
← C→
翻译中…

Problem Statement

翻译中…

$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.

翻译中…

Constraints

翻译中…
  • $N$ is an integer satisfying $1 \leq N \leq 10^5$.
  • $K$ is an integer satisfying $1 \leq K \leq 10^5$.
  • The length of the string $S$ is $N$.
  • Each character of the string $S$ is 0 or 1.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N K
S

翻译中…

Output

翻译中…

Print the maximum possible number of consecutive people standing on hands after at most $K$ directions.

翻译中…

样例

Input #1
5 1
00010
Output #1
4
We can have four consecutive people standing on hands, which is the maximum result, by giving the following direction: - Give the direction with $l = 1, r = 3$, which flips the first, second and third persons from the left.
Input #2
14 2
11101010110011
Output #2
8
Input #3
1 1
1
Output #3
1
No directions are necessary.
题目信息
题号
abc124_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。