Maximum worth

1

2 votes
Dynamic Programming, Algorithms, 3 Dimensional, Easy, 3D dynamic programming
Problem

There are  jewelry shops. Each jewelry shop has three types of coins, gold, platinum, and diamond. The worth of gold, platinum, and diamonds coins is , , and respectively. You decided to go to each of jewelry shops and take coins from each of the shops by satisfying the following conditions:

  1.  You can take at most  coin from an individual shop.
  2.  You can take at most  gold coins.
  3.  You can take at most  platinum coins. 
  4.  You can take at most  diamond coins.

You are required to collect coins from shops in such a way that the worth value of coins that are collected is maximized.

Input format

  • First line: An integer  denoting the number of jewelry shops
  • Second line: Three integers , and  denoting the maximum number of gold, platinum, and diamond coins respectively
  • Next  lines: Three space-separated integers , , and  denoting the worth value of the gold, platinum, and diamond coins respectively

Output format

Print a single integer representing the maximum worth value that you can get.

Constraints

 

Sample Input
4
2 1 1
5 4 5
4 3 2
10 9 7
8 2 9
Sample Output
27
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  • Gold coin from shop and  will be collected giving the worth value of .
  • Platinum coin from shop will be collected giving the worth value of .
  • Diamond coin from shop  will be collected giving the worth value of .
  • So the maximum worth value you can get is .
Editor Image

?