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: k2k \le 2 , F2: k10k \le 10 ).

You are given an integer nn . Find the minimum integer xx such that xnx \ge n and the number xx is kk -beautiful.

A number is called kk -beautiful if its decimal representation having no leading zeroes contains no more than kk different digits. E.g. if k=2k = 2 , the numbers 34344433434443 , 5555055550 , 777777 and 2121 are kk -beautiful whereas the numbers 120120 , 445435445435 and 998244353998244353 are not.

输入格式

The first line contains one integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases. Then tt test cases follow.

Each test case consists of one line containing two integers nn and kk ( 1n1091 \le n \le 10^9 , 1k101 \le k \le 10 ).

输出格式

For each test case output on a separate line xx — the minimum kk -beautiful integer such that xnx \ge n .

输入输出样例

  • 输入#1

    6
    2021 3
    177890 2
    34512 3
    724533 4
    998244353 1
    12345678 10

    输出#1

    2021
    181111
    34533
    724542
    999999999
    12345678
首页