Alex's social studies class just finished watching a video, so the lights in the classroom are dimmed. As he sits next to the light switches, his teacher asks him to turn them on.
His classroom is lit by one column of 1
represents an on light and 0
represents an off light. Each student sits directly below a light, and for each student to have enough light to work, there must be at least one light on within
Alex needs to turn lights on to give all students enough light, but his fingers are sore from too much programming, so he doesn't want to flip more switches than he needs to. Given the current configuration of light switches, can you determine the minimum number of lights he has to turn on?
Constraints
For all subtasks:
Subtask 1 [20%]
No lights will be turned on initially.
Subtask 2 [30%]
The row will start and end with an on light.
Subtask 3 [20%]
Subtask 4 [30%]
No additional constraints.
Input Specification
The first line will contain the integer
The second line contains the integer
The third line contains the string
Output Specification
The output will contain one integer, the minimum number of lights Alex has to turn on.
Sample Input
16
2
0001100000000001
Sample Output
3
Explanation for Sample
The unmodified configuration results in some students not having enough light. The distance of each student from the nearest on light is shown below:
Light Configuration: 0001100000000001
Distance from Light: 3210012345543210
Enough Light: NYYYYYYNNNNNNYYY
It can be proven that at least three lights must be turned on to give all students enough light. The following is an example of a correct configuration using three flips:
Light Configuration: 1001100001001001
Distance from Light: 0110012210110110
Enough Light: YYYYYYYYYYYYYYYY
Comments