#P3859. [TJOI2008] 小偷
[TJOI2008] 小偷
Description
The figure above shows the case of three rooms. The black parts are the doors connecting two adjacent rooms, numbered from left to right as . When the thief enters the storage through door , the timing system starts, and each door has its own closing time. Each room contains different kinds of gems. For each kind of gem, its value and the time the thief spends to take one are different. To simplify the problem, we assume the time to move between rooms is negligible, and the quantities of every kind of gem in all rooms are unlimited. What is the maximum total value of gems the thief can obtain while still being able to escape successfully?
Note: For each door, the thief must exit through it strictly before it closes.
Input Format
For each test case, the first line contains two integers and , representing that the storage has rooms and there are kinds of gems. The second line contains positive integers, where the -th integer denotes the closing time of door (doors are numbered from ). The next lines each contain three integers , and , meaning that this kind of gem is located in room , its value is , and it takes time for the thief to take one.
Output Format
Output the maximum total value of gems the thief can obtain while successfully escaping the storage.
3 4
9 5 5
0 1 2
1 2 2
2 3 2
2 5 3
8
Hint
Sample Explanation
Although the gem worth in room looks good, it is better to take two gems worth , and then take two gems worth in room , for a total value of .
Constraints and Conventions
For of the testdata, the number of rooms does not exceed , the closing time of each door does not exceed , the number of gem types does not exceed , and each value does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号