#P6767. [BalticOI 2012/2020] 玫瑰 (Day0)
[BalticOI 2012/2020] 玫瑰 (Day0)
Background
For special reasons, the other testdata sets of this problem should be submitted here.
Valentine always wins.
Problem Description
Valentine wants to buy roses for his girlfriends. There are two shops in front of him. Each shop has an unlimited number of roses, but they sell roses only in bundles. In the first shop, each bundle contains roses and costs money. In the second shop, each bundle contains roses and costs money.
Find the minimum amount of money Valentine needs to spend to buy at least roses.
You can understand it like this: if but buying roses costs less than buying roses, then Valentine will buy roses and give the extra roses to other girls. Yes, Valentine is very “playboy” (huaxin).
Input Format
One line with five integers , with meanings as described in the statement.
Output Format
One line with one integer representing the minimum cost.
5 1 4 3 6
12
22 2 3 10 14
31
Hint
Sample Explanation
For sample , Valentine can choose to buy bundles from the second shop.
For sample , Valentine can choose to buy bundle from the first shop and bundles from the second shop.
Constraints
This problem uses bundled tests.
- Subtask 1 (20 pts): .
- Subtask 2 (80 pts): no special restrictions.
For of the data, , , and it is guaranteed that the answer does not exceed .
Notes
Translated from BalticOI 2020 Day0 B Roses.
It is the same as BalticOI 2012 Day0 A.
Translated by ChatGPT 5