atcoder#ABC231E. [ABC231E] Minimal payments
[ABC231E] Minimal payments
Score : points
Problem Statement
There are kinds of coins used in the Kingdom of Atcoder: -yen, -yen, , -yen coins. Here, holds, and is a multiple of for every .
When paying for a product worth yen using just these coins, what is the minimum total number of coins used in payment and returned as change?
Accurately, when is an integer at least , find the minimum sum of the number of coins needed to represent exactly yen and the number of coins needed to represent exactly yen.
Constraints
- All values in input are integers.
- $1=A_1 < \ldots
- is a multiple of for every .
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 87
1 10 100
5
If we pay with one -yen coin and receive one -yen coin and three -yen coins as the change, the total number of coins will be .
2 49
1 7
7
It is optimal to pay with seven -yen coins.
10 123456789012345678
1 100 10000 1000000 100000000 10000000000 1000000000000 100000000000000 10000000000000000 1000000000000000000
233