#P6767. Minimum Cost to Buy Roses
Minimum Cost to Buy Roses
Minimum Cost to Buy Roses
Valentine wants to buy roses for his N girls. There are two shops selling bouquets of roses:
- The first shop sells bouquets containing exactly \(A\) roses for \(B\) dollars per bouquet.
- The second shop sells bouquets containing exactly \(C\) roses for \(D\) dollars per bouquet.
Valentine can buy any number of bouquets (possibly more than needed), and if he ends up with more than \(N\) roses, he will give the extra roses away. The task is to determine the minimum amount of money required to purchase at least \(N\) roses.
Input Format: A single line with five integers \(N\), \(A\), \(B\), \(C\), and \(D\).
Output Format: Output a single integer representing the minimum cost.
inputFormat
The input consists of one line containing five space-separated integers: \(N\), \(A\), \(B\), \(C\), and \(D\), where
- \(N\) is the minimum number of roses required,
- \(A\) is the number of roses per bouquet at the first shop,
- \(B\) is the cost of one bouquet at the first shop,
- \(C\) is the number of roses per bouquet at the second shop,
- \(D\) is the cost of one bouquet at the second shop.
outputFormat
Output a single integer which is the minimum cost needed to purchase at least \(N\) roses.
sample
10 3 2 4 3
7