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. css动画延迟好像有点怪

    项目中需要使用到动画animate.css,在自定义的时候发现设置animation-delay 和 animation-duration 的总时间不对会导致 动画缺失. 比如 bounceInLef ...

  2. asp.net web core 部署问题汇总

    记录所有部署时遇到的问题.    微软官网部署说明 转载自:.NET Core 3.0 构建和部署(测试过可以使用)   A    单文件可执行文件(文件体积较大,合并所有依赖)       asp. ...

  3. 关闭visual studio code 智能提示功能

    对于程序初学者来说,应该少用IDE的提示功能,因为这样有助于记住一些常用的函数等功能.这也是为什么戏称喜欢用notepad++(windows)或者vim编辑器(Linux)来开发代码是大神的原因,而 ...

  4. java的开发步骤----

    首先老师给了一个 视频给我:叫我理解java的简单开发步骤: 上两张图: 然后我就理解成了这样::: 简述java开发步骤:第一步: 编写源代码,把源代码写好 :第二部:源代码通过编译器编译成字节码c ...

  5. linux - 删除软件包

    # 参数e的作用是使rpm进入卸载模式,对名为[package name]的软件包进行卸载 rpm -e [package name] # 由于系统中各个软件包之间相互有依赖关系,使用-nodeps忽 ...

  6. matplotlib 的一些知识

    import matplotlib.pyplot as plt plt做图有两种方式,一种是面向对象编程方式的,一种是直接利用plt的结构化的快速绘图编程方式.所以命令不能用错地方. fig=plt. ...

  7. Python-selenium,使用SenKey模块时所碰到的坑

    一.SenKey模块(模拟鼠标键盘操作) :python3中没有该模块,使用PyUserInput模块代替 二.PyUserInput模块安装前需要安装:pywin32和pyHook模块,pywin3 ...

  8. Redis到底是多线程还是单线程?线程安全吗,还需要加锁吗?

    0. redis单线程问题 单线程指的是网络请求模块使用了一个线程(所以不需考虑并发安全性),即一个线程处理所有网络请求,其他模块仍用了多个线程. 1. 为什么说redis能够快速执行 (1) 绝大部 ...

  9. 通过css修改input的边框

    input{ border:1px solid #d2d2d2; background-color:transparent; } 可以看到主要是把背景色调成透明的颜色,从而来进行边框的设置

  10. 题解【洛谷P3478】[POI2008]STA-Station

    题面 设\(dp_i\)表示以\(i\)为根节点时所有节点的深度之和. 首先以 \(1\) 为根求出所有点深度之和\(dp_1\),并预处理每个点的子树大小. 设 \(v\) 是 \(u\) 的孩子, ...