Problems > Ones with K Flips

Ones with K Flips

Difficulty: 1500 3000 ms 128 MB

sliding-window two-pointers

You may flip at most K zeros to ones. Print the longest run of consecutive ones achievable.

Input: the first line has N and K; the second line has N values (0/1).

Output: the maximum achievable run of ones.

Constraints:

  • 1 ≤ N ≤ 105
  • 0 ≤ K ≤ N

Sample Tests

Input 1
11 2
1 1 1 0 0 0 1 1 1 1 0
Output 1
6
Input 2
3 0
0 0 0
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.