C. Get the Long Binary Number time limit per test1 second memory limit per test256…
- User
C. Get the Long Binary Number time limit per test1 second memory limit per test256 megabytes Consider a binary number x .Define c0(x) as the number of 0 in x ,c1(x) as the number of 1 in x .
For example,x=10100 ,we can get c0(x)=3,c1(x)=2 .
Now you're given a binary number y (without leading zero) of length n and an integer k .Your task is find the smallest binary number x (without leading zero),which satisfies:
y≤x ; c0(x)−c1(x)=k . Input The first line of input will contain a single integer t(1≤t≤105) , denoting the number of test cases.
Each test case consists of two line of input.
The first line contains two integers n,k(1≤n≤105,−105≤k≤105) .
The second line contains a binary number y (without leading zero) of length n .
The sum of n,|k| over all test cases will not exceed 4∗105 .
Output For each test case,output on a new line — the smallest binary number x (without leading zero),which satisfies:
y≤x ; c0(x)−c1(x)=k . Example InputСкопировать 5 1 -1 0 6 -4 110100 6 1 100000 7 1 1110000 10 -2 1011010111 OutputСкопировать 1 110111 1000011 1110000 1011011001 solve in c++
- Assistant