#P6746. 『MdOI R3』Operations
『MdOI R3』Operations
Description
Given non-negative integers , there are two operations:
- Choose any positive integer , subtract from both numbers. The cost of performing this operation once is .
- Choose any positive integer , multiply one of the two numbers by , and divide the other by and then take the floor. The cost of performing this operation once is .
Here, taking the floor means changing a number to the greatest integer that is not greater than it. For example, the floor of is , and the floor of is .
The chosen can be any positive integer. During the operations, and may become negative.
You may perform operations on these two numbers any number of times. Find the minimum total cost to turn both and into .
Input Format
One line with four integers , separated by spaces, representing the initial values of and the costs of the two operations.
Output Format
One line with one integer, the minimum cost.
9 36 1 3
4
Hint
[Sample Explanation]
First use operation once, choose , multiply by , and divide by , obtaining .
Then use operation once, choose , subtract from both numbers, obtaining .
It can be proven that there is no solution with a smaller total cost than the one above.
For more samples, please get them here.
[Constraints]
This problem uses bundled testdata, in other words, you can get the score of a subtask only if you pass all test points in that subtask.
| Subtask ID | Score | |||||
|---|---|---|---|---|---|---|
| 10 | ||||||
| 40 | ||||||
The special properties are as shown above, where means this special property is guaranteed, and a blank cell means it is not guaranteed.
For all data, .
Input Format
One line with four integers .
Output Format
One line with one integer.
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号