Minimum Amount Problem

4

6 votes
Implementation, Basic Programming, Dynamic Programming, Medium, Basics of Implementation
Problem

There are three types of fruits T1,T2, and T3 in a shop. Each fruit of type T1,T2, and T3 gives energy 2,3, and 5 respectively.
The number of fruits of type T1,T2, and T3 are Cnt1,Cnt2, and Cnt3 respectively and each fruit cost Cost1,Cost2, and Cost3 respectively.
You want to get a total of S energy by buying some of the fruits, but you want to spend as less as possible.
So, find the minimum amount you need to spend.
Print "-1" if the answer does not exist.
Input format
- First line : S represents total amount of energy.
- Second line : Three space-separated integers Cnt1, Cnt2, and Cnt3
- Third line : Three space-separated integers Cost1, Cost2, and Cost3

Output format
Print the answer.

Constraints
1S3×104
1Cnti7×103 for 1i3
1Costi7×103 for 1i3

Sample Input
10
2 2 1
5 5 20
Sample Output
20
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

We can make a total of energy 10 by two ways :-
Case 1 :- Buying two T1, two T2. So this will cost 20.
Case 2 :- Buying one T1, one T2, one T3, So this will cost 30.

So, the minimum is 20.

Editor Image

?