#P4095. [HEOI2013] Eden 的新背包问题
[HEOI2013] Eden 的新背包问题
Description
The amnesiac Eden keeps trying to recall the past, yet he can only clearly remember the feeling of longing, not her face or smile.
In his memory, she always liked giving Eden puzzles. On Valentine's Day night, while the two were strolling through a bustling street and gazing at the delicate dolls in a gift shop, she suddenly asked Eden a question: there are dolls. Each doll has a cost and a value, and each doll can be bought a limited number of times. With a fixed budget , how should one choose which dolls to buy and how many copies of each, so that the total cost does not exceed and the total value is maximized.
As is well known, this is a classic multiple knapsack problem. Eden solved it quickly, but she seemed a bit unhappy that her problem was answered so fast. So she made it harder: there will be multiple queries. In each query, a new budget is given and one doll is removed (i.e., that doll cannot be chosen). Then the answer to the multiple knapsack under this condition is asked (i.e., the problem described above).
Now Eden is in trouble, but he does not want to be stumped. Can you help him?.
Input Format
- The first line contains an integer , the number of dolls. Dolls are indexed starting from .
- The next lines, each line contains three integers. On line , the integers denote the cost of one copy of doll , the value obtained, and the purchase limit of doll , respectively.
- The next line contains an integer , the number of queries.
- The next lines, each contains two integers , indicating which doll is removed (note that dolls are indexed from ) and the new budget for this query. The removal does not persist, i.e., different queries are independent.
Output Format
Output lines. On the -th line, output the answer for the -th query.
5
2 3 4
1 2 1
4 1 2
2 1 1
3 2 3
5
1 10
2 7
3 4
4 8
0 5
13
11
6
12
4
Hint
Sample Explanation.
There are five types of dolls. Their costs, values, and purchase limits are , , , , .
There are five queries. Take the first query as an example.
The first query removes the doll with index , and asks for the maximum value when the budget is . The remaining dolls are , , , . If you buy copies of doll (i.e., all of them), and then buy one copy of doll , you spend exactly and the total value is . It can be proved that there is no better solution.
Note that you do not have to buy all available copies of a doll.
Constraints.
- For of the testdata, it is guaranteed that .
- Additionally, for of the testdata, it is guaranteed that , , .
- Additionally, for of the testdata, it is guaranteed that , .
- Additionally, for of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号