No.825 賢いお買い物
タグ : / 解いたユーザー数 214
作問者 :
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
Aoki lives in Country X. Two types of coins are used in Country X: $1$G and $10$G.
Aoki has now come shopping at a supermarket with $A$ $1$G coins and $B$ $10$G coins. This supermarket carries products priced at $1$G,$2$G,...,$10^{100}$G.
Aoki's goal is to buy one product with a positive price so that exactly $C$ coins in total remain in his wallet at the end.
However, he does not want to waste money, so he wants to achieve this by spending as little as possible.
Find the minimum price, in G, of the product he must buy.
He may pay in any way, as long as the coins come from his wallet and their total amount is at least the price of the product.
Change is returned using $1$G and $10$G coins in the composition that minimizes the total number of coins (it can be shown that this composition is uniquely determined).
Input
$A\ B\ C$
The first line contains $A,B$, the initial numbers of $1,10$G coins, and $C$, the target final number of coins, separated by spaces.
Constraints
- $0 \le A, B \le 20$
- $0 \le C \le 100$
- All inputs are integers.
Output
Output on one line the minimum price needed to achieve the goal.
However, if the goal cannot be achieved no matter how he shops, output "Impossible" (without the double quotation marks).
Print a newline at the end.
Sample
Sample 1
Input
3 10 9
Output
13
If he pays for a $13$G product with $3$ $1$G coins and $1$ $10$G coin, the change is $0$G, so 9 $10$G coins remain in his wallet.
Sample 2
Input
20 20 29
Output
2
If he pays for a $2$G product with 12 $1$G coins, the change is returned as 1 $10$G coin, so 8 $1$G coins and 21 $10$G coins remain in his wallet.
Sample 3
Input
1 0 1
Output
Impossible
He originally has $1$ coin, but this is impossible because he must pay a positive price.
Sample 4
Input
15 9 41
Output
Impossible
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。