Олимпиадный тренинг

Задача 34828. Wholesale is cheaper!


Задача

Темы:
A new mobile operator has started operating in Moscow, providing Internet access via 3G technology. The new operator offers simple and low
tariffs, in particular, one megabyte of Internet traffic costs 1 ruble. 

In addition, the operator offers to buy wholesale traffic packages – There are two offers: buy a traffic package for A megabytes for B rubles and buy a traffic package for C megabytes for D rubles.

Tanya plans to use N megabytes of Internet traffic within a month. Determine the minimum amount that she will have to pay. Tanya can acquire
any number of each of the two proposed packages, as well as pay for traffic at the rate of "1 ruble per megabyte". Tanya can purchase Internet traffic packages, including
if the total paid traffic is more than N megabytes, if it comes out cheaper.

The program receives as input five natural numbers N, A, B, C, D, written in & nbsp; separate lines, not exceeding 500,000 each. It is guaranteed that A > B and C > D.
The program should output a single integer – the minimum amount you need to pay to purchase N megabytes of traffic.
 
Input Output Note
35
10
9
20
17
31 A package for 10 megabytes costs 9 rubles, a package for 20 megabytes
costs 17 rubles. To pay for 35 megabytes, you need to buy a package
for 10 megabytes and a package for 20 megabytes, and for the remaining 5
megabyte pay 5 rubles.
 
55
30
20
20
16
40 A package for 30 megabytes costs 20 rubles, a package for 20 megabytes
costs 16 rubles. To pay for 55 megabytes, you need to buy two
package for 30 megabytes, which will cost 40 rubles in total.