Valentine has decided to congratulate all of his N girlfriends by giving each one a yellow rose. In the nearby flower market yellow roses are sold by exactly two vendors. Each of them has an unlimited amount of roses; however, they sell roses only in bouquets (so you can only buy a certain amount of roses at a time). At the first vendor you can buy a bouquet of A roses for B Euros; at the second vendor ? a bouquet of C roses for D Euros. A, B, C, and D are all positive integers.
If Valentine can buy more than N roses for a smaller amount of money than buying precisely N roses, he will buy more than N roses and gift the leftover to any of the two lovely salesgirls.
Write a program that calculates the minimum amount of money in Euros for which Valentine can buy at least N roses!
입력 5 1 4 3 6 출력 12 Comments Valentine will buy six roses - two bouquets at the second place. 입력 22 2 3 10 14 출력 31 Comments Valentine will buy one bouquet at the first place and two at the second.
출처:boi 2012 practice