#P6240. 好吃的题目
好吃的题目
Description
There is a snack street with shops arranged from left to right, numbered starting from .
Shop sells only one kind of snack, with calories and tastiness .
Now there are food lovers coming to the street. Food lover will look for snacks among shops in , and to avoid gaining too much weight, they can consume at most calories.
Eating too many snacks can get boring, so the snack from the same shop can be eaten at most once.
Each food lover wants to know the maximum total tastiness they can get.
Input Format
The first line contains two integers, representing and .
The second line contains integers; the -th integer is .
The third line contains integers; the -th integer is .
Lines to each contain three integers. In line , the integers , , and represent the parameters of the -th food lover.
Output Format
For each food lover, output one integer per line, representing the maximum sum of tastiness.
8 5
10 31 36 30 36 24 29 29
59 152 284 202 282 156 277 212
3 5 81
4 5 75
7 8 71
1 3 92
4 4 95
566
484
489
495
202
15 10
5 15 18 15 18 12 14 14 10 15 17 18 9 7 6
11 31 26 34 19 17 15 25 11 34 18 26 21 8 11
7 15 31
2 9 67
8 15 77
3 13 43
6 7 98
2 2 110
3 13 26
11 11 84
7 14 25
4 6 90
66
118
128
89
32
31
55
18
55
70
Hint
Sample Input/Output Explanation
Sample 1 Explanation
For the first food lover in the first set of testdata, they can choose shop and shop .
The consumed calories are , and the obtained tastiness is .
Sample 2 Explanation
For the first food lover in the second set of testdata, they can choose shops , , and .
The consumed calories are , and the obtained tastiness is .
Constraints
- For of the testdata, .
- For of the testdata, , .
- For of the testdata, , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号