CF1256D.Binary String Minimizing
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a binary string of length n (i. e. a string consisting of n characters '0' and '1').
In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than k moves? It is possible that you do not perform any moves at all.
Note that you can swap the same pair of adjacent characters with indices i and i+1 arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.
You have to answer q independent test cases.
输入格式
The first line of the input contains one integer q ( 1≤q≤104 ) — the number of test cases.
The first line of the test case contains two integers n and k ( 1≤n≤106,1≤k≤n2 ) — the length of the string and the number of moves you can perform.
The second line of the test case contains one string consisting of n characters '0' and '1'.
It is guaranteed that the sum of n over all test cases does not exceed 106 ( ∑n≤106 ).
输出格式
For each test case, print the answer on it: the lexicographically minimum possible string of length n you can obtain from the given one if you can perform no more than k moves.
输入输出样例
输入#1
3 8 5 11011010 7 9 1111100 7 11 1111100
输出#1
01011110 0101111 0011111
说明/提示
In the first example, you can change the string as follows: 11011010→10111010→01111010→01110110→01101110→01011110 .
In the third example, there are enough operations to make the string sorted.