#P8548. 小挖的买花
小挖的买花
Background
Xiao Wa likes buying flowers, but they are too lazy. So this task is completely handed over to you.
Problem Description
There are only flowers in the shop. Each flower has three attributes: price , beauty , and freshness .
Xiao Wa has different requirements each time. More precisely, for the -th purchase, the money you have can buy flowers with total cost at most . At the same time, Xiao Wa also requires that the total freshness is at least . Xiao Wa wants to know: after meeting these conditions, what is the maximum possible total beauty of the flowers you buy? If no matter what you do, you cannot make the total freshness at least , output .
Xiao Wa will ask you to buy flowers a total of times. Can you answer their questions correctly? The queries are independent of each other.
Input Format
The first line contains two positive integers .
Lines each contain three positive integers , representing the three attributes of a flower.
Lines each contain two positive integers , representing the requirements for each purchase.
Output Format
Output lines. Each line contains one integer, the maximum total beauty. If there is no solution, output .
5 1
2 4 5
4 3 3
1 3 2
3 4 3
3 2 5
10 10
15
Hint
For of the testdata, .
For of the testdata, , .
For of the testdata, , , .
For the other of the testdata, for each purchase, .
For of the testdata, , , , .
Translated by ChatGPT 5