#P10655. [ROI 2017] 反物质 (Day 2)
[ROI 2017] 反物质 (Day 2)
Problem Description
You have developed types of experiments to obtain antimatter. You cannot control the amount produced, but you can guarantee that the amount of antimatter obtained by the -th type lies within the interval , and the cost is . Each experiment type can be used multiple times.
All produced antimatter is stored in a container. After each experiment, you can learn the mass of antimatter in the container. The antimatter in the container must not exceed grams (otherwise it will explode).
If in the -th run of an experiment you obtain a total of units of antimatter, you can sell it to the military for a profit of rubles, where is the cost of that experiment.
Under the condition of ensuring safety, you want to know, in the worst case, what is the minimum profit you can guarantee.
Input Format
The first line contains two integers .
The next lines each contain three integers .
Output Format
Output one line with one integer, indicating the maximum profit you can guarantee.
1 17
4 6 10
11999999970
2 11
2 2 100
3 5 5
9999999890
Hint
Sample Explanation
For sample set #1:
We can only use experiment . If we run it once, the antimatter obtained lies in ; if we run it twice, it lies in . If we have obtained units of antimatter at this time, we cannot continue, because if the next run yields units, the container will explode. In other cases, we can continue with a third run, and the possible interval becomes .
At this point, no matter what, we cannot continue, for the same reason as above. So in the worst case we can only obtain units of antimatter and need to run the experiment three times. The profit is .
Constraints
Only part of the testdata is provided for this problem. If you need to judge against the full testdata, please go to LOJ P2772.
For all testdata, , .
| Subtask ID | Points | Special Restriction | ||
|---|---|---|---|---|
| None | ||||
| None | ||||
Note: The original problem has subtasks. For convenience, the last several subtasks that are identical except for the constraint on are merged into one subtask here.
Translated by ChatGPT 5