#P9215. [入门赛 #11] [yLOI2021] 扶苏与 1 (Hard Version)

    ID: 10345 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2023Special JudgeO2优化构造语言月赛

[入门赛 #11] [yLOI2021] 扶苏与 1 (Hard Version)

Background

The difference between this problem and the Easy Version is: the range of xx is different, and the length limit of yy is different.

Please note that the Easy Version and the Hard Version are not in a strict containment relationship.

In the contest ICPC2022 EC Final, within less than five minutes after the start, Fusu misread a problem, and turned a digit DP problem into an easy warm-up problem, completely tricking her teammates.

To avoid wasting the misread problem, it appears here.

Problem Description

Fusu gives you a number xx. You need to give her a number yy such that when performing the column addition x+yx + y, it produces exactly kk carries.

The length of your yy must not exceed the length of xx. (Note that this requirement is different from the Easy Version.)

The meaning of a carry is: in column addition, if the sum of the digits in the same column (plus any carry from the lower column) is greater than 99, then only the ones digit of this sum is kept in this column of the result, and we say this digit generates a carry to the higher column.

The picture below shows an example of column addition. The two digits marked in red in the result both generate carries upward.

Input Format

There are multiple groups of testdata in a single test point.

The first line contains an integer TT, representing the number of testdata groups.
Then follow TT groups of data. Each group has only two lines, with one integer per line.
The integer in the first line is xx.
The integer in the second line is kk.

Output Format

This problem uses special judge.

For each group of data, output one line with one integer, representing the yy you give.

If there are multiple valid yy, you may output any one of them. But you must satisfy the following three constraints:

  • yy is a positive integer.
  • yy has no leading 00.
  • The length of yy does not exceed the length of xx.

In particular, if such a yy does not exist, output one line with -1\texttt{-1}.

5
1
1
14
1
514
2
1234
1
123456
6
9
8
516
7
877777

Hint

Constraints

For all test points, it is guaranteed that 0x<10(104)0 \leq x < 10^{(10^4)}, 1T50001 \leq T \leq 5000, 1k1+log10max(1,x)1 \leq k \leq 1+\log_{10}\max(1,x). The input xx has no leading 00.

Notes

The input xx may be very large. If x<10tx < 10^t, then the length of the input xx will not exceed tt. The meaning of the formula k1+log10max(1,x)k \leq 1 + \log_{10}\max(1,x) in the constraints is that kk will not exceed the length of xx.

Translated by ChatGPT 5