#K12891. Maximum Consecutive Ones After K Flips
Maximum Consecutive Ones After K Flips
Maximum Consecutive Ones After K Flips
You are given a binary string of length N and an integer K. Your task is to determine the maximum number of consecutive '1's that can be obtained by flipping at most K '0's into '1's in the string.
More formally, given a binary string S of length N, you need to find the maximum length L such that there exists an interval [l, r] in the string satisfying:
$$\text{number of zeros in } S[l:r] \leq K \quad \text{and} \quad L = r - l + 1 $$You are required to implement a solution using a sliding window technique that reads input from standard input (stdin
) and writes the result to standard output (stdout
).
inputFormat
The input consists of two lines:
- The first line contains two integers, N and K, where N is the length of the binary string and K is the maximum number of flips allowed.
- The second line contains a binary string of length N consisting only of characters '0' and '1'.
outputFormat
Output a single integer representing the maximum number of consecutive '1's that can be produced by flipping at most K '0's.
## sample10 2
1101001100
5