#P3161. [CQOI2012] 模拟工厂

[CQOI2012] 模拟工厂

Description

There is a game called “Simulated Factory” as follows: at time 00, the factory’s productivity equals 11. At each time, you may either increase productivity or produce goods. If you choose to increase productivity, then at the next time the factory’s productivity increases by 11; if you choose to produce goods, then at the next time your number of goods increases by pp, where pp is the factory’s productivity at the current time.

There are nn orders, and you may choose to accept or reject each one. The ii-th order (ti,gi,mi)(t_i, g_i, m_i) requires delivering gig_i goods to the buyer at time tit_i. After completion, your goods decrease by gig_i, and your revenue increases by mim_i yuan. If you accept order ii, you must transact exactly at time tit_i, neither earlier nor later. Multiple orders may be accepted at the same time, but each order can be accepted at most once. Maximize the final total revenue.

For example, if there are two orders (5,1,8)(5,1,8) and (7,15,3)(7,15,3), the following strategy is optimal: at times 00, 11, 22 increase productivity (so the productivity at time 33 is 44), then at times 33 and 44 produce goods; at time 55 you will have 88 goods. Accept order 11 at this time (you will still have 77 goods left), and continue producing goods at times 55 and 66; then at time 77 you will have 7+4+4=157+4+4=15 goods, exactly meeting order 22.

Input Format

The first line contains an integer nn, the number of orders. Each of the following nn lines contains three integers ti,gi,mit_i, g_i, m_i.

Output Format

Output a single line with the maximum total revenue. The answer is guaranteed to fit in the 32-bit signed integer range.

2
5 1 8
7 15 3
11

Hint

Constraints

Index nn \le tit_i \le gig_i \le mim_i \le
131 \sim 3 55 100100 1000010000
464 \sim 6 1010
7107 \sim 10 1515 100000100000 10910^9

Translated by ChatGPT 5