#K66217. Minimum Substring Flips
Minimum Substring Flips
Minimum Substring Flips
You are given an integer n representing the length of a binary string s, an integer k representing the length of the substring to flip, and the binary string s consisting solely of characters '0' and '1'.
In one operation, you may choose an index i (0-indexed) and flip the bits in the substring starting at i and ending at min(i+k-1, n-1). A flip operation changes a '0' to a '1' and a '1' to a '0'. The goal is to transform s into a string of all zeros using the fewest number of operations.
In mathematical terms, given a binary string s, find the minimum number f of operations needed so that after performing the operations, the string satisfies:
inputFormat
The input is read from stdin and has the following format:
- The first line contains two integers n and k separated by a space, where n is the length of the binary string s and k is the length of the substring to be flipped.
- The second line contains the binary string s of length n.
outputFormat
Output a single integer to stdout which represents the minimum number of flip operations required to convert s into a string consisting only of '0's.
## sample5 3
00110
2