Vegetables

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

요약
채소 종류마다 단가, 첫 판매 보너스, 재고, 하루 부패량이 주어질 때, 하루 판매 상한 m으로 p일 동안 판매해 얻는 최대 이익을 구한다.
난이도

어려움10점 중 8점

유형
그리디, 힙, 정렬, 수학
정답자
아직 제출이 없습니다

문제

Little N is the administrator of the vegetable warehouse and is responsible for designing the sales plan of vegetables.

In the vegetable warehouse, there are nn kinds of vegetables stored in total. Little N needs to design a reasonable sales plan based on the characteristics of different vegetables and comprehensively consider various factors to obtain the most benefits.

When calculating the income from selling vegetables, for every unit of iith vegetable sold, you can get a_ia\_i income.

In particular, since the policy encourages merchants to conduct diversified sales, when selling the iith vegetable for the first time, they will also get an additional income of s_is\_i.

At the start of the operation, the stock of vegetable ii is c_ic\_i units.

However, the preservation time of vegetables is very limited, once they go bad, they cannot be sold, but the smart little N has calculated the time for each unit of vegetables to go bad: for the iith vegetable, there is a freshness value x_ix\_i, and there will be x_ix\_i units of vegetables going bad at the end of each day, until all vegetables go bad. (Note: The spoilage time of each unit of vegetables is fixed and does not change with sales)

Formally: for all positive integers dd satisfying the condition d×x_i≤c_id\times x\_i \leq c\_i, x_ix\_i units of vegetables will spoil at the end of dd day.

In particular, if (d−1)×x_i≤c_i<d×x_i(d - 1)\times x\_i \leq c\_i < d\times x\_i , then c_i−(d−1)×x_ic\_i - (d - 1)\times x\_i units of vegetables will spoil by the end of dd days.

Note that when x_i=0x\_i = 0, it means that this vegetable will not go bad.

At the same time, the total amount of vegetables sold every day is also limited, and cannot exceed mm units at most.

Now, Little N has kk query. Each query is of the form: Given p_jp\_j, if you need to sell for p_jp\_j days, what is the maximum profit you can get?

입력

The first line contains three positive integers n,m,kn, m, k, which respectively represent the number of types of vegetables, the upper limit of the total amount of vegetables that can be sold every day, and the number of questions raised by small N.

In the next nn lines, enter four non-negative integers in each line to describe the characteristics of a vegetable, which are a_i,s_i,c_i,x_ia\_i, s\_i, c\_i, x\_i in turn, and the meanings are as described above.

In the next kk lines, enter a non-negative integer p_jp\_j in each line, the meaning is as described above.

출력

Output kk lines, each line contains an integer, and the number in line ii represents the answer to question ii.

제한

  • n≤105n \le 10^5
  • m≤10m \le 10
  • p_j≤105p\_j \le 10^5

For all test data, it is guaranteed that p_jp\_j in kk sets of queries are different from each other.

For all test data, it is guaranteed that 0,0, 0\le s_i,x_i\le 10^9$.

예제1

  1. 예제 1

    입력
    2 3 2
    3 3 3 3
    2 5 8 3
    1
    3
    
    예상 출력
    16
    27