#P9644. BaoBao's Light Off Challenge
BaoBao's Light Off Challenge
BaoBao's Light Off Challenge
BaoBao wants to ensure a good night's sleep by turning off all the lights in his bedroom. His bedroom has \(n\) lights arranged in a row and numbered from 1 to \(n\). Each light can be either on or off initially. Every time, BaoBao can choose an integer \(i\) and then turn off all the lights from \(i\) to \(i+L-1\) (both inclusive), where \(L\) is a fixed positive integer for every operation.
Your task is to determine the smallest possible \(L\) such that BaoBao can turn off all the lights within at most \(k\) operations.
Note: If a light is already off, it remains off.
inputFormat
The input consists of two lines:
- The first line contains two space-separated integers \(n\) and \(k\) --- the number of lights and the maximum allowed operations.
- The second line contains a binary string of length \(n\) representing the initial status of the lights. The character '1' indicates that the light is on, while '0' indicates that it is off.
You can assume that \(1 \leq n \leq 10^5\) and \(1 \leq k \leq 10^5\).
outputFormat
Output a single integer --- the smallest possible \(L\) such that all the lights can be turned off within at most \(k\) operations.
sample
5 2
10101
3
</p>