You are given Chef's calendar for the next days, defined as a binary string of length where means that Chef has a holiday on the day from now, and means that Chef has to work on that day.
Chef wants to plan his vacations. For each vacation, Chef needs consecutive holidays in his calendar. Obviously, he can only go on one vacation at a time.
Chef can take at most one extra holiday. That is, he can flip at most one digit in from to . If he does this optimally, what is the maximum number of vacations that he can go on?
Input Format
- The first line of input contains a single integer , denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains two space-separated integers and .
- The second line of each test case contains a binary string of length — Chef's schedule.
Output Format
For each test case, output on a new line the answer — the maximum number of vacations Chef can take if he takes at most one more extra holiday.
Constraints
- The sum of across all test cases does not exceed
Sample Input 1
3
7 2
0010001
4 3
1010
5 2
00100
Sample Output 1
3
1
2
Explanation
Test Case : Chef can flip the digit to make his calendar . This allows him to take vacations in the first days.
Test Case : Chef can flip the digit to make his calendar . This allows him to take one vacation using the last days.
Test Case : Regardless of whether Chef flips the digit or not, he can take at most
Solution:
No comments:
Post a Comment