Devu and binary String

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Devu loves to play with binary strings a lot. One day he borrowed a binary string s of size n from his friend Churu. Before starting to play with it, he wants to make sure that string does not contain more than k consecutive equal characters. For achieving that, only kind of operation he is allowed to perform is to flip any i^{th} character of the string.
As Devu is always in hurry to meet his girlfriend, he wants you to help him in finding out the minimum number of operations he will need. Also he wants you to print one of the possible modified string too.
Input
 First line of input contains an integer T denoting the number of test cases.
 For each test case, there are two lines.
 First line contains two space separated integers n, k as defined in the problem.
 Next line contains string s of size n.
Output
 For each test case, print two lines.
 First line should contain an integer corresponding to minimum number of operations Devu needs.
 In second line, print one of the possible modified strings.
Constraints
Subtask #1: 20 points
 1 ≤ T ≤ 100, 1 ≤ n ≤ 20, 1 ≤ k ≤ n
Subtask #2: 35 points
 1 ≤ T ≤ 10^{2}, 1 ≤ n ≤ 10^{3}, 1 ≤ k ≤ n
Subtask #3: 45 points
 1 ≤ T ≤ 10^{5}, 1 ≤ n ≤ 10^{5}, 1 ≤ k ≤ n
 Sum of n over all the test cases is ≤ 10^{6}
Example
Input: 3 2 1 11 2 2 11 4 1 1001 Output: 1 10 0 11 2 1010
Explanation
Example case 1: As 1 is occurring twice consecutively, we can convert 11 to 10 in a single operation.
Example case 2: You don't need to modify the string as it does not have more than 2 equal consecutive character.
Example case 3: As 0 is occurring twice consecutively, we can convert 1001 to 1010 in a two operations (Flip third and fourth character).
Author:  admin2 
Editorial  http://discuss.codechef.com/problems/DEVSTR 
Tags  admin, admin2, basicmath, easy, may15 
Date Added:  9022015 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 