Live Programming
Time limit5sMemory limit512 MB
Choose a subset of songs within total length T and order them to maximize the sum of basic points minus squared feature differences between consecutive songs.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Sorting, Math, Greedy
- Solved
- No attempts yet
Problem
A famous Japanese idol group, JAG48, is planning the program for its next live performance. They have different songs, , , ..., and . Each song has three integer parameters, , , and : is the length of , is the basic satisfaction points the audience gets when is performed, and is the feature value of that affects the audience's satisfaction. During the live performance, JAG48 can perform any number (but at least one) of the songs, unless the total length of the chosen songs exceeds the length of the live performance . They can decide the order of the songs to perform, but they cannot perform the same song twice or more.
The goal of this live performance is to maximize the total satisfaction points the audience gets. In addition to the basic satisfaction points of each song, the difference between the feature values of two songs performed consecutively affects the total satisfaction points. If there is no difference, the audience feels comfortable. The larger the difference, however, the more frustrated the audience feels.
Thus, the total satisfaction points are calculated as follows:
- If is the first song of the live performance, the total satisfaction points just after is .
- If is the second or a later song and is performed just after , is added to the total satisfaction points, because the audience feels frustrated when and differ.
Help JAG48 find a program with the maximum total satisfaction points.
Input
The input is formatted as follows.
$N$ $T$
$t_1$ $p_1$ $f_1$
$\ldots$
$t_N$ $p_N$ $f_N$
The first line contains two integers and : the number of available songs (), and the length of the live performance ().
The following lines give the parameters of the songs. The -th of them contains three integers, the parameters of : the length (), the basic satisfaction points (), and the feature value ().
You can assume that at least one song has length at most .
Output
Output the maximum total satisfaction points the audience can get during the live performance.