Logo
(追記) (追記ここまで)

23524번 - Redistribution of Digits 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 256 MB1473100.000%

문제

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

Each of the next $t$ lines contains a string $s$ --- a given set of digits, integer $n$ --- quantity of numbers which should be formed and $n$ integers $a_i$ --- upper bounds for numbers. The digits for all numbers $a_i$ are given in a non-increasing order starting from the most significant digit. The set of digits and the numbers $a_i$ do not contain a digit 0ドル$.

출력

You are required to output $t$ 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 \le t \le 1000 $
  • $ 1 \le |s| \le 500 $
  • $ 1 \le n \le 50 $
  • $ 1 \le a_i \le 10^9 $

예제 입력 1

3
1234 2 21 43
12534 2 21 43
42 1 42

예제 출력 1

14 23
-1
42

힌트

출처

Contest > Open Cup > 2018/2019 Season > Stage 18: Grand Prix of Minsk B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /