#P4164. [JSOI2010] 挖宝藏
[JSOI2010] 挖宝藏
Description
JP does not train properly, and he has become addicted to another game—treasure hunting.
In the game, there are treasures buried in an infinite 2D grid. Each treasure has value and is located at .
A grid cell is diggable if it satisfies one of the following conditions:
- .
- The three cells , , and have all been dug already.
The cost to dig one cell is . When a treasure is dug out, you are considered to have obtained its value. Please help JP find the maximum profit, i.e., value minus cost. (It is also possible to dig no treasure, with profit .)
Input Format
The first line contains , the number of treasures.
The next lines each contain three integers , representing the position and value of a treasure.
Output Format
Output one integer in a single line, representing the maximum profit.
5
1 -1 2
0 -1 2
4 -1 1
3 -1 2
2 -1 2
4
Hint
Sample Explanation 1
Dig treasures No. . The total value is , the total cost is , so the profit is . It can be proven that there is no better plan.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号