#P7302. [NOI1998] 免费的馅饼
[NOI1998] 免费的馅饼
Problem Description
SERKOI has recently released a game called "Free Pies". The game is played on a stage. The stage has a width of cells (numbered from to from left to right), and the player occupies one cell. At the beginning, the player may stand anywhere on the stage and holds a tray. The figure below shows a moment when the ceiling height is cells and the player is catching pies.

After the game starts, pies continuously appear from the top cells of the stage ceiling and fall straight down. The player moves left and right to catch the pies. Each second, the player may move or cells to the left, move or cells to the right, or stay in place.
If at some moment a pie arrives exactly at the cell where the player is standing, the player collects that pie. If a pie lands in a cell where the player is not present, the pie disappears.
Write a program to help the player collect pies so that the sum of the scores of the collected pies is maximized.
Input Format
The first line contains two positive integers separated by spaces, giving the stage width and the number of pies .
The next lines each provide information about one pie.
Each line contains three positive integers, which are: the time when the pie reaches the stage, the index of the cell where it falls, and the score value .
The game starts at time .
In the input file, adjacent items on the same line are separated by one space.
In the input data, it is possible that two pies have the same and .
Output Format
Output one number, representing the maximum total score the player can obtain.
3 4
1 2 3
5 2 3
6 3 4
1 1 5
12
Hint
For of the data, , , , , 。
Translated by ChatGPT 5