LUNAPARK
A theme park is planning to install new recreational activities. The engineers have identified a set of possible locations along an imaginary straight line. Each location is suitable for a specific activity, the installation of which yields a specific profit. For each activity installed, space must be provided for public entry and exit. To make the best use of space, the entry and exit areas of neighboring activities can overlap, while entry and exit spaces have been secured for the first and last activity, respectively. However, the installation of one activity may exclude the installation of other activities in neighboring positions before and after it.
For example, consider a small park with candidate positions. In the first position, a roller coaster can be installed with a daily profit of euros. The roller coaster requires empty positions to the right as an exit area. In the second position, bumper cars can be installed with a daily profit of euros. The bumper cars require one empty position to the left and one empty position to the right. In the third position, the "octopus" ride can be installed with a daily profit of euros. The "octopus" requires one empty position to the left and one empty position to the right. In the fourth position, a trampoline can be installed with a daily profit of euros. The trampoline requires one empty position to the left. The optimal solution is to install the bumper cars in the second position and the trampoline in the last position, yielding a daily profit of euros.
The park's engineers need our help in selecting the activities to be installed in order to maximize the park's profit. Write a program that solves the engineers' problem.
Input
The program should read from the standard input a positive integer , corresponding to the number of activities in the park. From the next lines, the program will read integers corresponding (in the order given) to the profit generated by installing activity , and the number of empty positions to the left and to the right required for installing activity . The activities are numbered based on their position along the line, from left to right.
Output
An integer corresponding to the maximum profit for the business.
Constraints
Bonus There will be an extra input example for which:
- Time Limit: 1 sec.
- Maximum available memory: 64 MB.
Example of Input - Output
STDIN (lunapark.in)
5
80 0 1
60 1 1
90 1 2
100 2 1
70 1 0
STDOUT (lunapark.out)
180
Comments