#P7396. 自动兑换机(2021 CoE-I D)

自动兑换机(2021 CoE-I D)

Problem Description

The metro company of Mca City has decided to adopt a new measure: no need to buy tickets, just insert coins and board. It is rumored that this is to reduce the time passengers spend queuing to buy tickets. The metro operator contacted the city's Association for Computing Machinery (ACM), specifically the Automated Checkout Machine (ACM) company under it, and asked them to develop an Automatic exChange Machine (ACM) to meet passengers' needs. They hired you as the chief programmer to write the program for this machine.

Inside the automatic exchange machine, there are coins of various denominations. When a passenger inserts a banknote into the machine, the machine will automatically exchange it into coins of equal value according to the coin denominations currently available. Of course, passengers do not want to carry a large pile of coins to squeeze into the metro, so the fewer coins, the better. If the existing coin denominations cannot complete the exchange, you should output one line of information telling the passenger to seek service at a manual counter.

Input Format

The input contains multiple test cases.

The first line contains an integer TT, indicating the number of test cases. Each test case is one line: the first is an integer cc, indicating the number of coin denomination types, followed by cc integers, where each integer di1icd_i(1 \leq i \leq c) denotes a coin denomination in cents, and finally a real number mm, denoting the total value of the banknote to be exchanged, in dollars.

Output Format

For each input line, output one line. If no exchange scheme exists, output No solution.. Otherwise, output an exchange scheme with the minimum number of coins in the following format: first output the total number of coins in the scheme, then a space, and then print the exchange sequence in the format shown in the samples, i.e., in increasing order of denomination, output each denomination used in the scheme and its corresponding number of coins. If there are multiple schemes with the minimum number of coins, output the scheme with the smallest lexicographical order (i.e., according to ASCII order).

6
6 1 2 5 10 20 50 25.31
5 1 2 2 5 10 0.18
5 1 2 10 9 5 0.18
6 2 5 10 20 50 100 0.03
11 173 151 214 211 238 167 385 179 5 235 112 46.1
13 95 180 285 205 164 82 122 52 362 260 166 364 189 6.55
53 1*1+10*1+20*1+50*50
4 1*1+2*1+5*1+10*1
2 9*2
No solution.
14 112*2+151*1+385*11
4 122*1+164*1+180*1+189*1

Hint

Sample Explanation

In the first test case, there are 66 coin denominations: 11 cent, 22 cents, 55 cents, 1010 cents, 2020 cents, and 5050 cents. You need to exchange 25.3125.31 dollars (25312531 cents). The scheme with the minimum number of coins is: 5050 coins, 11 coin of 11 cent, 11 coin of 1010 cents, 11 coin of 2020 cents, and 5050 coins of 5050 cents.

In the second test case, there are 55 coin types, but only 44 distinct denominations: 11 cent, 22 cents, 55 cents, and 1010 cents. You need to exchange 0.180.18 dollars (1818 cents). The scheme with the minimum number of coins is: 44 coins, 11 coin of 11 cent, 11 coin of 22 cents, 11 coin of 55 cents, and 11 coin of 1010 cents.

In the third test case, there are 55 coin denominations: 11 cent, 22 cents, 55 cents, 99 cents, and 1010 cents. You need to exchange 0.180.18 dollars (1818 cents). The scheme with the minimum number of coins is: 22 coins, 22 coins of 99 cents.

In the fourth test case, there is no exchange scheme that meets the requirements. Output: No solution..

In the fifth test case, the minimum number of coins is 1414, and there are the following three exchange schemes:

14 112*2+151*1+385*11
14 167*1+179*2+235*1+385*10
14 173*2+179*1+235*1+385*10

According to the statement, the following is the lexicographically smallest scheme:

14 112*2+151*1+385*11

In the sixth test case, the minimum number of coins is 44, and there are the following seven exchange schemes:

4 52*2+189*1+362*1 
4 82*1+122*1+166*1+285*1 
4 95*2+180*1+285*1 
4 95*2+205*1+260*1 
4 95*1+166*1+189*1+205*1
4 122*1+164*2+205*1
4 122*1+164*1+180*1+189*1

According to the statement, the following is the lexicographically smallest scheme:

4 122*1+164*1+180*1+189*1

Constraints and Conventions

For 100%100\% of the testdata, 1T4001c1001 \leq T \leq 400,1 \leq c \leq 1001di4001 \leq d_i \leq 4000<m1000 \lt m \leq 100. The real number mm representing the total value of the banknote to be exchanged has three cases: no decimal point (an integer), one digit after the decimal point, or two digits after the decimal point.

When outputting the exchange sequence, the same coin denomination should be merged. For example, suppose the correct output is:

4 111*2+222*2

Then the following outputs do not meet the requirements:

4 111*1+111*1+222*2
4 111*2+222*1+222*1
4 111*1+111*1+222*1+222*1

Translated by ChatGPT 5