시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 22 | 16 | 15 | 71.429% |
Ahmad is shopkeeper working in a market. When a customer pays him for his shopping, he has to pay back the changes. Ahmad always wants to pay with the highest bills (if possible). Write a program to help Ahmad.
First line contains T the number of test cases (0 < T < 100). Each test case has two lines. First one is the amount M (1 ≤ M ≤ 1000000) that Ahmad should pay be to customer. Second line contains m1:a1,...,mi:ai,mn:an (1 ≤ m ≤ 1000000), mi is the money bill and ai is the number of bills he has for each mi.
Print the bills (sorted in descending) that Ahmad needs to pay back to the customers.
3 235 5:10,10:6,20:4,50:3 370 10:4,5:20,40:4,70:3,100:2,50:5 172 10:4,5:20,40:4,70:3,100:2,50:5
Customer1: 50 3 20 4 5 1 Customer2: 100 2 70 2 10 3 Customer3: Impossible