Redistribution of Digits
시간 제한1초메모리 제한256 MB
문자열 s의 모든 자릿수를 정확히 한 번씩 사용해 n개의 수를 만들되, 각 수가 a_i 이하가 되도록 배분한다.
문제
You are required to form numbers based on a given set of digits. Each number is also provided with an upper bound. Each digit from the given set must be used exactly once. If the set does not contain a digit, you are not allowed to use it.
입력
First line contains an integer --- the number of tests.
Each of the next lines contains a string --- a given set of digits, integer --- quantity of numbers which should be formed and integers --- upper bounds for numbers. The digits for all numbers are given in a non-increasing order starting from the most significant digit. The set of digits and the numbers do not contain a digit .
출력
You are required to output lines containing the given quantity of numbers corresponding the conditions above. If a solution does not exist you should print "-1". If there are multiple solutions, you may output any of them.