T1:
# include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
long long a[N];
string s, s1;
long long q, n, k;
int main() {
scanf("%lld", &q);
while (q--) {
scanf("%lld%lld", &n, &k);
cin >> s;
long long cnt = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == '0') {
a[cnt++] = i;
}
}
for (long long i = 0; i < cnt; i++) {
if (k >= a[i] - i) {
k -= (a[i] - i);
a[i] = i;
} else {
a[i] -= k;
k = 0;
}
}
s1 = s;
for (long long i = 0; i < n; i++) {
s1[i] = '1';
}
for (long long i = 0; i < cnt; i++) {
s1[a[i]] = '0';
}
cout << s1 << endl;
s = "";
s1 = "";
}
return 0;
}
T2:
# include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int flag = 1;
cin >> a >> b >> c >> d;
for (int j = b; j >= a; j--) {
for (int k = c; k >= b; k--) {
for (int l = c; l <= d; l++) {
if ((j + k) > l && (j + l) > k && (k + l) > j) {
printf("%d %d %d\n", j, k, l);
flag = 0;
break;
}
}
if (flag == 0) {
break;
}
}
if (flag == 0) {
break;
}
}
}
return 0;
}
T3:
# include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d %d", &n, &m);
if (n == 1 or m == 1) {
printf("1 1\n");
} else if (n <= 3 and m <= 3) {
printf("2 2\n");
} else {
printf("%d %d\n", n, m);
}
}
return 0;
}
T4:
# include <bits/stdc++.h>
using namespace std;
string s = "codeforces";
char c, c1;
int t;
int main() {
cin >> t;
int len = s.size();
for (int i = 0; i < t; i++) {
cin >> c;
bool flag = 1;
for (int j = 0; j < len; j++) {
if (c == s[j]) {
flag = 0;
printf("YES\n");
break;
}
}
if (flag) {
printf("NO\n");
}
}
return 0;
}
T5:
# include <bits/stdc++.h>
using namespace std;
long long t, n, cnt, hi;
int main() {
cin >> t;
while (t--) {
cin >> n;
cnt = 0;
for (int i = 0; i < n; i++) {
cin >> hi;
if (hi == 1) {
cnt += 1;
}
}
cout << n - cnt / 2 << endl;
}
return 0;
}
T6:
# include <bits/stdc++.h>
using namespace std;
long long a, b, n, m, sum1, sum2, ans;
int main() {
int t;
cin >> t;
while (t--) {
cin >> a >> b >> n >> m;
sum1 = n / (m + 1);
sum2 = n % (m + 1);
ans = sum1 * min(a * m, b * (m + 1)) + sum2 * min(a, b);
printf("%lld\n", ans);
}
return 0;
}
T7:
# include <bits/stdc++.h>
using namespace std;
int main () {
long long n, m, a;
cin >> n >> m >> a;
cout << (long long) (ceil (1.0 * n / a) * ceil (1.0 * m / a));
return 0;
}
T8:
# include <bits/stdc++.h>
using namespace std;
int n, k[1001], N = -100000000000;
string name[1001];
map <string, int> m;
map <string, int> a;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> name[i] >> k[i];
m[name[i]] += k[i];
a[name[i]] += k[i];
}
for (int i = 0; i < n; i++) {
N = max(N, m[name[i]]);
m[name[i]] = 0;
}
for (int i = 0; i < n; i++) {
m[name[i]] += k[i];
if (m[name[i]] >= N && a[name[i]] == N) {
cout << name[i];
return 0;
}
}
return 0;
}
T9:
# include <bits/stdc++.h>
using namespace std;
string s1, s2;
int main() {
cin >> s1 >> s2;
int xa = s1[0] - 'a' + 1;
int ya = s1[1] - '0';
int xb = s2[0] - 'a' + 1;
int yb = s2[1] - '0';
int n = max(abs(xa - xb), abs(ya - yb));
printf("%d\n", n);
while (n--) {
if (xa > xb && ya > yb) {
xa--;
ya--;
printf("LD\n");
continue;
}
if (xa > xb && ya == yb) {
xa--;
printf("L\n");
continue;
}
if (xa > xb && ya < yb) {
xa--;
ya++;
printf("LU\n");
continue;
}
if (xa == xb && ya > yb) {
ya--;
printf("D\n");
continue;
}
if (xa == xb && ya < yb) {
ya++;
printf("U\n");
continue;
}
if (xa < xb && ya > yb) {
xa++;
ya--;
printf("RD\n");
continue;
}
if (xa < xb && ya == yb) {
xa++;
printf("R\n");
continue;
}
if (xa < xb && ya < yb) {
xa++;
ya++;
printf("RU\n");
continue;
}
}
}
T10:
# include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
if (n == 2) {
printf("NO");
} else if (n % 2 == 0) {
printf("YES");
} else {
printf("NO");
}
return 0;
}
T11:
# include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int cnt = 0;
cin >> s;
for (int i = 0; i <= s.size(); i++) {
if (s[i] == '4' || s[i] == '7') {
cnt++;
}
}
if (cnt == 4 || cnt == 7) {
printf("YES");
} else {
printf("NO");
}
return 0;
}
T12:
# include <bits/stdc++.h>
using namespace std;
string s;
const int N = 5010;
int a[N], b[N];
int main() {
cin >> s;
int len = s.size();
if (s[0] == 'a') {
a[0]++;
} else {
b[0]++;
}
for (int i = 1; i < len; i++) {
a[i] = a[i - 1];
b[i] = b[i - 1];
if (s[i] == 'a') {
a[i]++;
} else {
b[i]++;
}
}
if (len == 1) {
printf("1");
return 0;
}
int mx = 0;
for (int i = 0; i < len; i++) {
for (int j = i + 1; j < len; j++) {
if (i - 1 < 0) {
int cnt = a[i] + b[j] + (a[len - 1] - a[j - 1]);
mx = max(mx, cnt);
} else {
int cnt = a[i] + (b[j] - b[i - 1]) + (a[len - 1] - a[j - 1]);
mx = max(mx, cnt);
}
}
}
printf("%d", mx);
return 0;
}
T13:
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
if (!k) {
if (a[0] > 1) {
printf("1");
return 0;
} else {
printf("-1");
return 0;
}
}
if (a[k] == a[k - 1]) {
printf("-1");
return 0;
}
printf("%d", a[k - 1]);
return 0;
}