Vegetables
시간 제한1초메모리 제한1024 MB
채소 종류마다 단가, 첫 판매 보너스, 재고, 하루 부패량이 주어질 때, 하루 판매 상한 m으로 p일 동안 판매해 얻는 최대 이익을 구한다.
문제
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 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 th vegetable sold, you can get income.
In particular, since the policy encourages merchants to conduct diversified sales, when selling the th vegetable for the first time, they will also get an additional income of .
At the start of the operation, the stock of vegetable is 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 th vegetable, there is a freshness value , and there will be 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 satisfying the condition , units of vegetables will spoil at the end of day.
In particular, if , then units of vegetables will spoil by the end of days.
Note that when , 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 units at most.
Now, Little N has query. Each query is of the form: Given , if you need to sell for days, what is the maximum profit you can get?
입력
The first line contains three positive integers , 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 lines, enter four non-negative integers in each line to describe the characteristics of a vegetable, which are in turn, and the meanings are as described above.
In the next lines, enter a non-negative integer in each line, the meaning is as described above.
출력
Output lines, each line contains an integer, and the number in line represents the answer to question .
제한
For all test data, it is guaranteed that in sets of queries are different from each other.
For all test data, it is guaranteed that 0\le s_i,x_i\le 10^9$.