0

There are N jewellery shop(s). Each jewellery shop has three kinds of coins - Gold, Platinum, and Diamond having worth value A, B, and C respectively. You decided to go to each of N jewellery shop and take coins from each of the shop. But to do so following conditions must satisfy -

You can take at most 1 coin from an individual shop. You can take at most X coins of Gold type. You can take at most Y coins of Platinum type. You can take at most Z coins of Diamond type. You want to collect coins from shops in such a way that worth value of coins collected is maximised.

Input Format :

The first line contains an integer N. Where N is the number of jewellery shops. The second line contains three integers X, Y, Z. Where X, Y, Z denotes the maximum number of coins you can collect of type Gold, Platinum, and diamond respectively. Then N lines contain three space-separated integers A, B, C. Where A, B, C is the worth value of the Gold, Platinum, and diamond coin respectively.

Output Format :

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

Constraints :

1 <= N <= 200

1 <= X , Y , Z <= N

1 <= A , B , C < 10 9

Example : -

4 2 1 1 5 4 5 4 3 2 10 9 7 8 2 9

Answer:-

27(9+9+5+4)

I tried the obvious greedy approach but it failed :-)

sdrtg ghytui
  • 433
  • 3
  • 12
  • Is this related? https://stackoverflow.com/questions/55437293/maximize-consumption-energy – גלעד ברקן Apr 02 '19 at 21:13
  • Tysm :-) How did you find it?!! I got this question from a guy on Codechef. Btw, I would like to say, that you have unknowingly helped me a lot to in being good at dp,memoization, lots of thanks ! God Bless! And you write very good answers on dp always! I think Stack overflow should reward you with prizes!:-) – sdrtg ghytui Apr 02 '19 at 21:32
  • Lol. Thanks. I'm still working on the PR question... – גלעד ברקן Apr 02 '19 at 21:39
  • I came to know that it is 100% digit-dp problem, I'll learn that topic :-) Thanks again:p – sdrtg ghytui Apr 02 '19 at 21:46
  • 1
    From the [help/on-topic]: *Questions asking for homework help **must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it**.* – Ken White Jul 05 '19 at 19:38

0 Answers0