Round Number
Time limit2sMemory limit256 MB
For each query, decide whether removing exactly k digits from x can leave a number with no leading zeros that is divisible by 100, and if so print one such result.
- Level
Medium5 of 10
- Topics
- Greedy, Implementation, String, Math
- Solved
- No attempts yet
Problem
Everyone likes round numbers. There are many reasons for this, the main one being that a number divisible by, say, 100 is much easier to remember. Unfortunately, round numbers are far rarer in our lives than all the others. First-grader Petya is very upset about this. So he came up with his own definition of a round number.
By Petya's definition, a number is round only if exactly digits can be removed from it so that the resulting number has no leading zeros but is divisible by 100. For example, with , the number 10304 is round, but the number 1000 is not.
Now Petya wants to know which numbers are round for which and which are not. Help him.
Input
The first line contains an integer , the number of pairs of numbers and that Petya wants to know about. The next lines each contain two positive integers and . Every is strictly less than the number of digits in the corresponding . Every has no leading zeros. The total number of digits across all does not exceed .
Output
For each pair and from the input, print -1 if the number is not round for the given . If the number is round for the given , print the number with exactly digits crossed out, after which it became divisible by 100. The number you print must not contain leading zeros, but it may be equal to zero.