You are given a binary string of length nn (i. e. a string consisting of nn 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 kk 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 ii and i+1i+1 arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.

You have to answer qq independent test cases.

Input

The first line of the input contains one integer qq (1≤q≤1041≤q≤104) — the number of test cases.

The first line of the test case contains two integers nn and kk (1≤n≤106,1≤k≤n21≤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 nn characters '0' and '1'.

It is guaranteed that the sum of nn over all test cases does not exceed 106106 (∑n≤106∑n≤106).

Output

For each test case, print the answer on it: the lexicographically minimum possible string of length nn you can obtain from the given one if you can perform no more than kk moves.

Example
input

Copy
3
8 5
11011010
7 9
1111100
7 11
1111100
output

Copy
01011110
0101111
0011111
Note

In the first example, you can change the string as follows: 110–––11010→10–––111010→011110–––10→01110–––110→0110–––1110→01011110110_11010→10_111010→011110_10→01110_110→0110_1110→01011110.

In the third example, there are enough operations to make the string sorted.

尽量把0往前移动

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int q;
cin >> q;
while (q--) {
int n;
long long k;
cin >> n >> k;
string s;
cin >> s;
int j = ;
for (int i = ; i < n; i++) {
if (j < i) j = i;
while (j < n && s[j] != '') j++; //判断前面某个0前面有几个1
if (j < n && j - i <= k) {//判断能否直接换过去
swap(s[i], s[j]);
k -= j - i;
}
}
cout << s << endl;
}
return ;
}

Codeforces Round #598 (Div. 3) D. Binary String Minimizing的更多相关文章

  1. Codeforces Round #598 (Div. 3) D. Binary String Minimizing 贪心

    D. Binary String Minimizing You are given a binary string of length n (i. e. a string consisting of ...

  2. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  3. Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划

    Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划 [Problem Description] 给你\( ...

  4. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

  5. Codeforces Round #598 (Div. 3)

    传送门 A. Payment Without Change 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/4 21:19:19 */ #i ...

  6. Codeforces Round #598 (Div. 3) A,B,C,D{E,F待补}

    A. Payment Without Change   #include<bits/stdc++.h> using namespace std; #define int long long ...

  7. Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)

    题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...

  8. Codeforces Round #303 (Div. 2) B. Equidistant String 水题

    B. Equidistant String Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/54 ...

  9. Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum

    E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...

随机推荐

  1. fastadmin选择下拉框

    fastadmin中要做下拉框的效果如下: 数据库中数据: 在对应model中添加一个方法: 控制器中添加一行: 在目录lang/zh-cn中找到你控制器名称所对应的文件添加配置: 在add.html ...

  2. 关于整合ssh中的细节03

    关于spring中提供的一些工具类和监听介绍 一.spring提供了一个HibernateTemplate类 ①HibernateTemplate类: 用于操作PO对象,类似Hibernate Ses ...

  3. 创建登录WEB UI页面的Business role.

    1: Define business role 2:  business role 中可以指定 config key,  该config key可以用于UI configurationo determ ...

  4. Java大全-吐血整理

    gqzdev

  5. 添加Usb3.0驱动到win7/8/10的usb安装光盘

    文章中所有需要使用到的软件和资源在文章末尾的网盘连接中有下载 Run the DISM GUI Tool Right-click on DISM GUI.exe and select Run as A ...

  6. Centos7安装python3.6.5

    安装python3.6.5,原来的python2.7.5并存 准备环境: 登录你的linux虚拟机或者云服务器,进入命令行界面如下图: 进入这样的窗口就是远程登录成功,我这里使用的是远程连接工具xsh ...

  7. C++-hihoCode1545-小Hi和小Ho的对弈游戏[树上Nim]

    #include <set> #include <map> #include <cmath> #include <queue> #include < ...

  8. python HTMLparser

    1.概述 如果我们要编写一个搜索引擎,第一步是用爬虫把目标网站的页面抓下来, 第二步就是解析该HTML页面,看看里面的内容到底是新闻.图片还是视频. 假设第一步已经完成了,第二步应该如何解析HTML呢 ...

  9. tomcat8.5和redis实现session共享

    1. 问题 ​ 由于之前看其他资料配置的session共享没注意自己tomcat的版本所以出现了诸多问题,tomcat8.5和之前版本的配置是不一样的. 2. 配置 ​ ①将如图所示三个jar包放入t ...

  10. MonoBehaviour单例的另外一种省事的写法

    using UnityEngine; public class CommSystem: SingletonGeneric<CommSystem> { public static strin ...