#P1782. 旅行商的背包

旅行商的背包

Description

Little S firmly believes that any problem can be solved in polynomial time, so he decides to be a traveling salesman for once. Before setting off, he bought some items. There are nn types of items; for the ii-th type, the volume is ViV_i, the value is WiW_i, and there are DiD_i items available. His knapsack has a capacity of CC. How should he pack to obtain the maximum total value? As a top guru, he solved this easily.

However, just before departure, he received another batch of special goods. There are mm such goods, and for the ii-th one, the relationship between its value YiY_i and the allocated volume XiX_i is: Yi=aiXi2+biXi+ciY_i = a_i X_i^2 + b_i X_i + c_i. This is good news, but Little S does not know how to handle it, so he turns to a super guru (that is, you) to help him solve this problem.

Input Format

The first line contains three integers n,m,Cn, m, C, as described above.
The next nn lines each contain three integers Vi,Wi,DiV_i, W_i, D_i, as described above.
The next mm lines each contain three integers ai,bi,cia_i, b_i, c_i, as described above.

Output Format

Output a single line: the maximum value.

2 1 10
1 2 3
3 4 1
-1 8 -16
10

Hint

Sample explanation:
Take all of the first two types of items. Allocate volume 44 to the last special good. The total value is $2 \times 3 + 4 \times 1 + (-1) \times 16 + 8 \times 4 + (-16) = 10$.

Constraints and Notes
For 100%100\% of the testdata, 1n1041 \le n \le 10^4, 1m51 \le m \le 5, 1C1041 \le C \le 10^4, 1Wi,Vi,Di10001 \le W_i, V_i, D_i \le 1000, 1000ai,bi,ci1000-1000 \le a_i, b_i, c_i \le 1000.

Translated by ChatGPT 5