CF1811A.Insert Digit

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have a positive number of length nn and one additional digit.

You can insert this digit anywhere in the number, including at the beginning or at the end.

Your task is to make the result as large as possible.

For example, you have the number 7654376543, and the additional digit is 44. Then the maximum number you can get is 765443765443, and it can be obtained in two ways — by inserting a digit after the 33th or after the 44th digit of the number.

你有一个长度为 nn 的正整数,以及一个额外的数字。

你可以将这个额外的数字插入到该数的任意位置(包括最前面或最后面)。

你的任务是使插入后得到的数尽可能大。

例如,你拥有的数是 7654376543,额外的数字是 44。那么你能得到的最大数是 765443765443,它可以通过两种方式获得:将该数字插入原数的第 33 位之后,或第 44 位之后。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The descriptions of the test cases follow.

The first line of the description of each test case contains two integers nn and dd (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 0≤d≤90 \le d \le 9) — the length of the number and an additional digit, respectively.

The second line of the description of each test case contains a string consisting of nn digits — the number that you have initially. It is guaranteed that the number does not contain leading zeros.

It is guaranteed that the sum of nn for all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

接下来是各测试用例的描述。

每个测试用例的描述的第一行包含两个整数 nn 和 dd(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;0≤d≤90 \le d \le 9)—— 分别表示数字的长度和一个额外的数字。

每个测试用例的描述的第二行包含一个由 nn 个数字组成的字符串 —— 即你初始拥有的数字。保证该数字不包含前导零。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a string consisting of n+1n + 1 digits — the maximum possible number that can be obtained.

对于每个测试用例,输出一个由 n+1n + 1 位数字组成的字符串——即所能得到的最大可能数字。

输入输出样例

  • 输入#1

    11
    5 4
    76543
    1 0
    1
    2 5
    44
    3 6
    666
    5 6
    13579
    5 8
    97531
    19 4
    9876543210123456789
    5 7
    73737
    8 1
    20000000
    7 0
    7058959
    12 1
    828127127732

    输出#1

    765443
    10
    544
    6666
    613579
    987531
    98765443210123456789
    773737
    210000000
    70589590
    8281271277321

输入解题思路,AI测评打分。不知道怎么写?

首页