CF1560F2.Nearest Beautiful Number (hard version)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
It is a complicated version of problem F1. The difference between them is the constraints (F1: k≤2 , F2: k≤10 ).
You are given an integer n . Find the minimum integer x such that x≥n and the number x is k -beautiful.
A number is called k -beautiful if its decimal representation having no leading zeroes contains no more than k different digits. E.g. if k=2 , the numbers 3434443 , 55550 , 777 and 21 are k -beautiful whereas the numbers 120 , 445435 and 998244353 are not.
输入格式
The first line contains one integer t ( 1≤t≤104 ) — the number of test cases. Then t test cases follow.
Each test case consists of one line containing two integers n and k ( 1≤n≤109 , 1≤k≤10 ).
输出格式
For each test case output on a separate line x — the minimum k -beautiful integer such that x≥n .
输入输出样例
输入#1
6 2021 3 177890 2 34512 3 724533 4 998244353 1 12345678 10
输出#1
2021 181111 34533 724542 999999999 12345678