MetaOA #19
Max Consecutive Ones III (for E5 :)
估计中等可在线判题
考点(AI 标注)双指针滑窗
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.
输入格式
The first line contains n k (1≤n≤100000, 0≤k≤n); the second line contains n values, each 0 or 1.
输出格式
Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.
样例 1
输入:
11 2
1 1 1 0 0 0 1 1 1 1 0
输出:
6
样例 2
输入:
1 0
0
输出:
0
样例 3
输入:
3 3
1 0 1
输出:
3
样例说明
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.