#P1794. 装备运输

装备运输

Description

After relaxing its offensive against the United Kingdom, Germany turned its spearhead to the east—the Soviet Union. In early 19431943, the fighting on the Eastern Front reached a white-hot stage. According to reliable intelligence, more than 9090 ten-thousands of German troops were preparing a massive offensive at Kursk. Therefore, Marshal Zhukov requires you to immediately transport a large amount of equipment from the Far East military factories to support the Kursk front. The train driver tells you that a single train can hold at most VV volume of weapons and equipment, but you might not be able to fill it up because the train cannot withstand that much weight; a single train can carry at most GG units of weight. Meanwhile, the factory warehouse provides you with an equipment list detailing each item's volume, weight, and firepower. To effectively support Marshal Zhukov, you need to find a plan that maximizes the total firepower.

Input Format

The first line contains two integers VV and GG, representing the maximum volume and weight.

The second line contains an integer NN, representing that the warehouse has NN pieces of equipment.

The 33-rd to N+2N+2-th lines each contain 33 numbers Ti,Vi,GiT_i,V_i,G_i, representing each equipment's firepower, volume, and weight.

Output Format

Output a single number, representing the maximum total firepower that can be obtained.

6 5 
4
10 2 2
20 3 2 
40 4 3 
30 3 3 

50

Hint

Constraints: For 100%100\% of the testdata, 1V,G,N5001\le V, G, N \le 500, 1Ti,Vi,Gi1091 \leq T_i, V_i, G_i \leq 10^9.

Translated by ChatGPT 5