Computer Purchase Return
InterviewTime limit2sMemory limit512 MB
Choose exactly one component of each of T types so the total cost stays within budget B and the total value is maximized.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Array, Implementation, Brute force
- Solved
- No attempts yet
Problem
You want to build your own computer to get the best value. The computer is made of () different types of components, and it must contain exactly one component of each type.
Each component has an integer cost (), an integer value (), and a type ().
An online parts store offers different components () to choose from.
For a given budget (), maximize the total value of the components in your computer while keeping the total cost at most .
If you cannot build such a computer, print .
Input
The first line contains , the number of component types your computer requires.
The next line contains . Then lines follow, each containing three integers , , and separated by single spaces.
The last line contains the budget .
Output
Print the maximum total value of a computer whose total cost is at most . If no valid computer can be built, print .
Hint
For the sample, choosing the components with cost and cost gives a computer with value , and no other combination reaches a higher value.