← 返回 amazon 的题目列表Max Consecutive ON Servers
类型:online_judge
Given an array serverStates of length n where serverStates[i] is the state of the i-th server (0=OFF, 1=ON), and an integer k. You may perform at most k operations, each flipping a server from OFF to ON (i.e., change one 0 to 1).
Return the length of the longest contiguous subarray consisting of only 1s after at most k flips.
Input (stdin)
Line 1: two integers n and k
Line 2: n integers (0/1) for serverStates
Output (stdout)
One integer: the maximum length of consecutive ON servers
Constraints
1 <= n <= 2*10^5
0 <= k <= n
serverStates[i] ∈ {0,1}
Examples
(see Chinese section for 5 test cases)
Example
Input
7 1
1 0 1 1 0 1 0
Output
4