Gas and Minerals
InterviewTime limit1sMemory limit1024 MB
Given minerals and gas budgets and n building types with costs and defense values, unbounded knapsack with two resource constraints finds the maximum total defense.
- Level
Medium4 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
An artifact that could turn the tide of the war was discovered in one of the distant Terran colonies. Meanwhile, the intelligence service reports that a Zerg swarm is moving toward the colony. The artifact must be protected at all costs before reinforcements arrive.
You have units of minerals and units of Vespen gas. There are types of defensive buildings available for construction. A building of type requires units of minerals and units of gas to construct, and increases the defenses of the base by units. You may construct any number of buildings of any type, including zero, as long as the total minerals and total gas spent do not exceed and , respectively.
Determine the maximum total defense capability that can be achieved under these constraints.
Input
The first line contains three integers , , and , the units of minerals and gas available and the number of building types (, , ).
The -th of the following lines contains three integers , , and , the units of minerals and gas needed to construct a building of type , and its defense value (, , ).
Output
Print a single integer, the maximum total defense capability that can be achieved.