306824: CF1256D. Binary String Minimizing

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Binary String Minimizing

题意翻译

## 题目描述 给定一个长度为n的二进制串(即由n个'0'和'1'构成的字符串),你最多可以进行k次交换相邻两个字符的操作。 一共q组询问。 ## 输入格式 第一行一个整数q(1≤q≤1e4),为测试用例的数量。 每组测试数据的第一行为两个整数,字符串的长度n和可以执行的移动次数k。 每组测试数据的第二行为一个由'0'和'1'构成的长度为n的字符串。 ## 输出格式 对于每个测试数据,请输出对原字符串进行不超过k次交换操作后的**字典序**最小的字符串。

题目描述

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 \le q \le 10^4 $ ) — the number of test cases. The first line of the test case contains two integers $ n $ and $ k $ ( $ 1 \le n \le 10^6, 1 \le k \le n^2 $ ) — 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 $ 10^6 $ ( $ \sum n \le 10^6 $ ).

输出格式


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: $ 1\underline{10}11010 \rightarrow \underline{10}111010 \rightarrow 0111\underline{10}10 \rightarrow 011\underline{10}110 \rightarrow 01\underline{10}1110 \rightarrow 01011110 $ . In the third example, there are enough operations to make the string sorted.

Input

题意翻译

## 题目描述 给定一个长度为n的二进制串(即由n个'0'和'1'构成的字符串),你最多可以进行k次交换相邻两个字符的操作。 一共q组询问。 ## 输入格式 第一行一个整数q(1≤q≤1e4),为测试用例的数量。 每组测试数据的第一行为两个整数,字符串的长度n和可以执行的移动次数k。 每组测试数据的第二行为一个由'0'和'1'构成的长度为n的字符串。 ## 输出格式 对于每个测试数据,请输出对原字符串进行不超过k次交换操作后的**字典序**最小的字符串。

加入题单

上一题 下一题 算法标签: