Vegetables - MarisaOJ: Marisa Online Judge
You are managing a store selling vegetables and have to plan the sales. There are n types of vegetables, and each unit of vegetable type i sold will earn ai. Furthermore, to enhance diversity, the first time selling vegetable type i will receive an additional si.
On the first day, vegetable type i has ci units. However, the freshness of vegetable type i is xi, meaning at the end of each day, xi units will wither. Moreover, each day, you cannot sell more than m units of vegetables.
The director asks you k questions. For the j-th question, a non-negative integer pj is asked, inquiring about the maximum profit if you have to sell for pj days.
### Input
- The first line consists of three integers n,m,k.
- The next n lines, the i-th line contains four integers ai,si,ci,xi.
- The next k lines, the j-th line contains a non-negative integer pj.
### Output
- Output k lines, the i-th line is the answer to the i-th question.
### Example
Input:
2323333258313
Output:
1627
Explanation:
- For the case of 1 day: Buy 1 unit of vegetable type 2 and 2 units of vegetable type 1.
- For the case of 3 days:
+ On the first day, buy 3 units of vegetable type 1, earning 12. At the end of the day, there are still 5 units of vegetable type 2.
+ On the second day, buy 3 units of vegetable type 2, earning 11. There should be 3 units of vegetable type 2 withering at the end of the day, but we sold them, leaving 2 units of vegetable type 2.
+ On the third day, sell the remaining 2 units of vegetable type 2, earning 4, making the total 12+11+4=27.
### Constraints
- Condition 1: All si values are 0.
- Condition 2: All xi values are 0.
- Ensure distinct values for each pj.
- 0≤ai,ci,si,xi≤109.
Test |
n |
m |
pj |
Condition 1 |
Condition 2 |
1 |
≤2 |
≤10 |
≤103 |
No |
2 |
≤3 |
3 |
≤4 |
4 |
≤103 |
≤2 |
5 |
≤3 |
6 |
≤4 |
7 |
≤4 |
≤1 |
8 |
≤6 |
≤2 |
≤6 |
9 |
≤8 |
≤1 |
≤8 |
10 |
≤10 |
≤2 |
≤10 |
11 |
≤20 |
≤3 |
≤20 |
12 |
≤102 |
≤10 |
≤102 |
Yes |
No |
13 |
No |
Yes |
14 |
No |
15 |
16 |
≤103 |
≤103 |
Yes |
Yes |
17 |
No |
18 |
No |
Yes |
19 |
No |
20 |
21 |
≤105 |
≤105 |
Yes |
Yes |
22 |
No |
23 |
No |
Yes |
24 |
No |
25 |
Topic
Greedy
Rating
2400
Solution (0)
Solution