#P3826. [NOI2017] 蔬菜

[NOI2017] 蔬菜

Description

Xiao N is the administrator of a vegetable warehouse, responsible for designing a sales plan for the vegetables.

There are nn types of vegetables stored in the warehouse. Xiao N needs to design a reasonable sales plan by considering various factors based on the characteristics of different vegetables, in order to obtain the maximum profit.

When calculating the profit from selling vegetables, for each unit of the ii-th vegetable sold, a profit of aia_i is obtained.

In particular, due to policies that encourage diversified sales, the first time the ii-th vegetable is sold, an additional bonus profit of sis_i is also obtained.

At the beginning of operations, the inventory of the ii-th vegetable is cic_i units.

However, vegetables have a very limited freshness period. Once spoiled, they cannot be sold. Fortunately, Xiao N has already calculated the spoilage time of each unit of vegetable: for the ii-th vegetable, there exists a freshness parameter xix_i. At the end of each day, xix_i units of this vegetable will spoil, until all units have spoiled. (Note: The spoilage time of each unit is fixed and does not change due to sales.)

Formally: for every positive integer dd such that d×xicid \times x_i \leq c_i, there will be xix_i units of the ii-th vegetable spoiling at the end of day dd.

In particular, if (d1)×xici<d×xi(d - 1) \times x_i \leq c_i < d \times x_i, then ci(d1)×xic_i - (d - 1) \times x_i units of the ii-th vegetable will spoil at the end of day dd.

Note that when xi=0x_i = 0, it means this vegetable never spoils.

Meanwhile, the total number of vegetables that can be sold per day is limited to at most mm units.

Now, Xiao N has kk questions and asks for your help. Each question is: given pjp_j, if sales last for pjp_j days, what is the maximum profit that can be obtained?

Input Format

The first line contains three positive integers n,m,kn, m, k, representing the number of vegetable types, the maximum total number of vegetable units that can be sold per day, and the number of questions asked by Xiao N, respectively.

The next nn lines each contain four non-negative integers describing the characteristics of one type of vegetable, in the order ai,si,ci,xia_i, s_i, c_i, x_i, with meanings as described above.

The next kk lines each contain one non-negative integer pjp_j, with the meaning as described above.

Output Format

Output kk lines. The number on the ii-th line is the answer to the ii-th question.

2 3 2
3 3 3 3
2 5 8 3
1
3

16
27

Hint

Sample Explanation

There are two types of vegetables:

For the 11-st vegetable, the profit per unit sold is 33, and an additional bonus profit of 33 is obtained when selling this vegetable for the first time. There are 33 units in total, and all of them will spoil at the end of day 11.

For the 22-nd vegetable, the profit per unit sold is 22, and an additional bonus profit of 55 is obtained when selling this vegetable for the first time. There are 88 units in total, among which 33 units spoil at the end of day 11, 33 units spoil at the end of day 22, and 22 units spoil at the end of day 33.

If sales last for 11 day, you should sell 22 units of the first vegetable and 11 unit of the second vegetable.

In this case: the profit from selling the first vegetable is 2×3+32 \times 3 + 3; the profit from selling the second vegetable is 1×2+51 \times 2 + 5; the total profit is (2×3+3)+(1×2+5)=16(2 \times 3 + 3) + (1 \times 2 + 5) = 16.

If sales last for 33 days, on day 11 you should sell 33 units of the first vegetable, on day 22 you should sell 33 units of the second vegetable (choose the 33 units that will spoil at the end of day 22), and on day 33 you should sell 22 units of the second vegetable.

In this case: the profit from selling the first vegetable is 3×3+33 \times 3 + 3; the profit from selling the second vegetable is (3+2)×2+5(3 + 2) \times 2 + 5; the total profit is (3×3+3)+[(3+2)×2+5]=27(3 \times 3 + 3) + [(3 + 2) \times 2 + 5] = 27.

Constraints

::cute-table{tuack} | Test point ID | nn | mm | pjp_j | Feature 11 | Feature 22 | | :-----------: | :---------: | :-------: | :--------: | :---------: | :---------------: | | 11 | 2\le 2 | 10\le 10 | 103\le 10^3 | No | No | | 22 | 3\le 3 | ^ | ^ | ^ | ^ | | 33 | 4\le 4 | ^ | ^ | ^ | ^ | | 44 | 103\le 10^3 | ^ | 2\le 2 | ^ | ^ | | 55 | ^ | ^ | 3\le 3 | ^ | ^ | | 66 | ^ | ^ | 4\le 4 | ^ | ^ | | 77 | 4\le 4 | 1\le 1 | ^ | ^ | ^ | | 88 | 6\le 6 | 2\le 2 | 6\le 6 | ^ | ^ | | 99 | 8\le 8 | 1\le 1 | 8\le 8 | ^ | ^ | | 1010 | 10\le 10 | 2\le 2 | 10\le 10 | ^ | ^ | | 1111 | 20\le 20 | 3\le 3 | 20\le 20 | ^ | ^ | | 1212 | 102\le 10^2 | 10\le 10 | 102\le 10^2 | Yes | ^ | | 1313 | ^ | ^ | ^ | No | Yes | | 1414 | ^ | ^ | ^ | ^ | No | | 1515 | ^ | ^ | ^ | ^ | ^ | | 1616 | 103\le 10^3 | ^ | 103\le 10^3 | Yes | Yes | | 1717 | ^ | ^ | ^ | ^ | No | | 1818 | ^ | ^ | ^ | No | Yes | | 1919 | ^ | ^ | ^ | ^ | No | | 2020 | ^ | ^ | ^ | ^ | ^ | | 2121 | 105\le 10^5 | ^ | 105\le 10^5 | Yes | Yes | | 2222 | ^ | ^ | ^ | ^ | No | | 2323 | ^ | ^ | ^ | No | Yes | | 2424 | ^ | ^ | ^ | ^ | No | | 2525 | ^ | ^ | ^ | ^ | ^ |

Feature 11: all sis_i are 00.

Feature 22: all xix_i are 00.

For all testdata, it is guaranteed that the pjp_j in the kk queries are pairwise distinct.

For all testdata, it is guaranteed that 0<ai,ci1090 < a_i, c_i \le 10^9, 0si,xi1090 \le s_i, x_i \le 10^9.

Translated by ChatGPT 5