Spiderman in Trouble
The Amazing Spiderman wants to create web fluid for himself before fight with Electro. He initially has
of web fluid. Spiderman wants to create
of web fluid. So he can change the amount of fluid in 3 different ways -:
- Double the amount of fluid.
- Increase the fluid by
. - Decrease the fluid by
.
Now, all the above operations have different costs associated with them
respectively for above operations. Help spiderman in finding the minimum cost to generate
of fluid starting from
of fluid.
Note: You need to generate exactly
of web fluid.
Input
Each test case contains 2 lines. First lines contains an integer N Second lines contains 3 space separated integers
, and
Output
Print an integer denoting the minimum cost incurred
Maximize
of web fluid.
Any leads on solving the problem is appreciated . Tried a dynamic programming approach but didnt work correctly.