아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Redistribution of Digits

시간 제한1초메모리 제한256 MB

요약
문자열 s의 모든 자릿수를 정확히 한 번씩 사용해 n개의 수를 만들되, 각 수가 a_i 이하가 되도록 배분한다.
난이도

보통10점 중 6점

유형
그리디, 구현, 정렬
정답자
아직 제출이 없습니다

문제

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 tt --- the number of tests.

Each of the next tt lines contains a string ss --- a given set of digits, integer nn --- quantity of numbers which should be formed and nn integers a_ia\_i --- upper bounds for numbers. The digits for all numbers a_ia\_i are given in a non-increasing order starting from the most significant digit. The set of digits and the numbers a_ia\_i do not contain a digit 00.

출력

You are required to output tt 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.

제한

  • 1≤t≤10001 \le t \le 1000
  • 1≤∣s∣≤5001 \le |s| \le 500
  • 1≤n≤501 \le n \le 50
  • 1≤a_i≤1091 \le a\_i \le 10^9

예제1

  1. 예제 1

    입력
    3
    1234 2 21 43
    12534 2 21 43
    42 1 42
    
    예상 출력
    14 23
    -1
    42