Gas and Minerals

면접 대비

시간 제한1초메모리 제한1024 MB

요약
광물과 가스 예산, 그리고 비용과 방어력을 가진 최대 10종류의 건물이 주어질 때, 각 종류를 원하는 만큼 지어 총 방어력을 최대로 만든다.
난이도

보통10점 중 6점

유형
동적 계획법, 그리디, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

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 towards the colony. It is necessary to protect the Artifact at all costs before the arrival of reinforcements.

You have mm units of minerals and gg units of Vespen gas. In addition, there are nn types of defensive buildings available for construction. A building of type ii requires a_ia\_i units of minerals and b_ib\_i units of gas to construct, and increases the defenses of the base by c_ic\_i units. You can construct any number of buildings (including zero) of any type, provided that the total costs of minerals and gas for all buildings will not exceed mm and gg, respectively.

Determine what the maximum total building defense capability can be achieved under the given constraints.

입력

The first line contains three integers mm, gg and nn --- the number of available units of minerals and gas, respectively, and the number of building types (0≤m≤10000 \le m \le 1000, 0≤g≤10000 \le g \le 1000, 1≤n≤101 \le n \le 10).

The ii th of the following nn lines contains three integers a_ia\_i, b_ib\_i and c_ic\_i --- the amount of units of mineral and gas are needed to construct a building of the ii-th type and its defenses (1≤a_i≤1001 \le a\_i \le 100, 0≤b_i≤1000 \le b\_i \le 100, 0≤c_i≤1000 \le c\_i \le 100).

출력

Print a single integer --- the maximum total building defense capability that can be achieved.

힌트

In the first example, the optimum is provided by the construction of one building of type 22 and one building of type 33.

In the second example, it is most profitable to construct one building of type 11 and two buildings of type 33.

예제2

  1. 예제 1

    입력
    10 10 3
    7 0 6
    6 2 7
    2 5 5
    
    예상 출력
    12
    
  2. 예제 2

    입력
    11 10 3
    7 0 6
    6 2 7
    2 5 5
    
    예상 출력
    16