#atcoderABC054D. Mixing Experiment
Mixing Experiment
Problem Statement
Dolphin is planning to generate a small amount of a certain chemical substance C.
In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of .
He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy.
The pharmacy sells kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock.
The package of chemical contains grams of the substance A and grams of the substance B, and is sold for yen (the currency of Japan).
Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C.
Find the minimum amount of money required to generate the substance C.
If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact.
Constraints
- , , , and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C, print -1
instead.
Input 1
3 1 1
1 2 1
2 1 2
3 3 10
Output 1
3
The amount of money spent will be minimized by purchasing the packages of chemicals and .
In this case, the mixture of the purchased chemicals will contain grams of the substance A and grams of the substance B, which are in the desired ratio: .
The total price of these packages is yen.
Input 2
1 1 10
10 10 10
Output 2
-1
The ratio of the two substances A and B cannot be satisfied by purchasing any combination of the packages. Thus, the output should be -1
.