A15779 | Insert Digit
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You have a positive number of length $n$ 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 $76543$ , and the additional digit is $4$ . Then the maximum number you can get is $765443$ , and it can be obtained in two ways — by inserting a digit after the $3$ th or after the $4$ th digit of the number.
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 $76543$ , and the additional digit is $4$ . Then the maximum number you can get is $765443$ , and it can be obtained in two ways — by inserting a digit after the $3$ th or after the $4$ th digit of the number.
输入格式
The first line contains a single integer $t$ ( $1 \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 $n$ and $d$ ( $1 \le n \le 2 \cdot 10^5$ ; $0 \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 $n$ 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 $n$ for all test cases does not exceed $2 \cdot 10^5$ .
The descriptions of the test cases follow.
The first line of the description of each test case contains two integers $n$ and $d$ ( $1 \le n \le 2 \cdot 10^5$ ; $0 \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 $n$ 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 $n$ for all test cases does not exceed $2 \cdot 10^5$ .
输出格式
For each test case, output a string consisting of $n + 1$ digits — the maximum possible number that can be obtained.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted