#P3718. Minimizing Unbeauty of Light Sequence
Minimizing Unbeauty of Light Sequence
Minimizing Unbeauty of Light Sequence
You are given n lights arranged in a row. Each light is either on (represented by 1) or off (represented by 0). The unbeauty of a configuration is defined as the length of its longest contiguous block of lights that are all in the same state (either all on or all off).
You are allowed to perform at most k operations. In each operation, you may choose any light and flip its state (i.e. turn it on if it was off, or off if it was on). Your task is to minimize the unbeauty of the configuration by performing at most k flips.
Note on formulas: All formulas must be represented in LaTeX format. For instance, the number of lights is given by $n$, and the allowed number of flips is $k$. The unbeauty is defined as the maximum length of any consecutive segment of identical lights, i.e., $\max\{\text{length of contiguous segments}\}$.
Determine the minimum possible unbeauty that can be achieved.
inputFormat
The first line of input contains two integers $n$ and $k$ --- the number of lights and the maximum number of flips allowed.
The second line contains a string of length $n$ consisting only of the characters '0' and '1'. Here, '1' represents a light that is on, and '0' represents a light that is off.
outputFormat
Output a single integer --- the minimum possible unbeauty (i.e. the minimized length of the longest contiguous block of identical lights) after at most $k$ flips.
sample
5 1
00000
2