cswork / OAOpen practice workspace

MetaOA #19

Max Consecutive Ones III (for E5 :)

Estimated MediumJudge-ready

Topics (AI-labelled)Two Pointers

Given a binary array, you may flip at most k 0s to 1s. Find the length of the longest run of consecutive 1s after the operation; you do not have to use all the flips.

Input

The first line contains n k (1≤n≤100000, 0≤k≤n); the second line contains n values, each 0 or 1.

Output

Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.

Example 1

Input:

11 2
1 1 1 0 0 0 1 1 1 1 0

Output:

6

Example 2

Input:

1 0
0

Output:

0

Example 3

Input:

3 3
1 0 1

Output:

3

Example notes

Example 1: flipping the two 0s at indices 4 and 5 turns the range [4,9] into 6 consecutive 1s; there is no longer range containing only two 0s.

Editorial

Loading solution…