#P4026. [SHOI2008] 循环的债务

    ID: 2858 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2008各省省选上海枚举,暴力背包

[SHOI2008] 循环的债务

Description

Alice, Bob, and Cynthia are always troubled by the messy debts among them. One day, they decide to sit together and settle everything. However, checking the authenticity of banknotes is troublesome, so they decide to exchange as little cash as possible when paying off their debts.

For example, Alice owes Bob 1010 yuan, while Cynthia owes neither of them anything. Suppose Alice has one 5050 yuan note, Bob has three 1010 yuan notes and ten 11 yuan notes, and Cynthia has three 2020 yuan notes. A straightforward way is: Alice gives the 5050 yuan to Bob, and Bob gives change back to Alice. In total, 1414 banknotes are exchanged. But this is not optimal. The optimal way is: Alice gives the 5050 to Cynthia, Cynthia gives two 2020 notes to Alice and one 2020 note to Bob, and Bob gives one 1010 note to Cynthia. In this case, only 55 banknotes are exchanged.

Before long, they find this is a hard problem, so they ask you, who are good at math, to solve it for them.

Input Format

The first line contains three integers: x1x_1, x2x_2, x3x_3 (1,000x1,x2,x31,000-1,000 \le x_1, x_2, x_3 \le 1,000), where

x1x_1 is the amount Alice owes Bob (if x1x_1 is negative, it means Bob owes Alice),

x2x_2 is the amount Bob owes Cynthia (if x2x_2 is negative, it means Cynthia owes Bob),

x3x_3 is the amount Cynthia owes Alice (if x3x_3 is negative, it means Alice owes Cynthia).

Then there are three lines, each containing 6 natural numbers:

a100,a50,a20,a10,a5,a1 a_{100}, a_{50}, a_{20}, a_{10}, a_5, a_1

b100,b50,b20,b10,b5,b1 b_{100}, b_{50}, b_{20}, b_{10}, b_5, b_1

c100,c50,c20,c10,c5,c1 c_{100}, c_{50}, c_{20}, c_{10}, c_5, c_1

a100a_{100} is the number of 100100 yuan banknotes Alice has, b50b_{50} is the number of 5050 yuan banknotes Bob has, and so on. We also guarantee a10+a5+a130a_{10} + a_5 + a_1 \le 30, b10+b5+b130b_{10} + b_5 + b_1 \le 30, c10+c5+c130c_{10} + c_5 + c_1 \le 30, and the total face value of all banknotes owned by the three people does not exceed 1,0001,000.

Output Format

If the debts can be fully settled, output the minimum number of banknotes that need to be exchanged. If they cannot be settled, output impossible.

10 0 0
0 1 0 0 0 0
0 0 0 3 0 10
0 0 3 0 0 0
5
-10 -10 -10
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0

Hint

For 30%30\% of the testdata, x1,x2,x350x_1, x_2, x_3 \le 50.

For 100%100\% of the testdata, x1,x2,x31,000x_1, x_2, x_3 \le 1,000.

Translated by ChatGPT 5