#P12463. [Ynoi Easy Round 2018] 星野瑠美衣
[Ynoi Easy Round 2018] 星野瑠美衣
Background

Problem Description
Hoshino Rubii likes to wander on a 2D plane. She is always on integer grid points, and each step can only choose one of up, down, left, or right (that is, increase or decrease the -coordinate or -coordinate by ).
For integer points on the plane, we call the tour they describe a process where Hoshino Rubii starts from , visits in order, and then returns to . The minimum number of steps Hoshino Rubii needs for a tour is called the tour’s excitement value.
Now Hoshino Rubii wants to take a tour. She first chooses integer points on the plane, and plans to insert some additional points among them to determine the sequence of points her next tour must pass through.
So she finds another integer points on the plane. Each point has a profit (possibly negative). She may choose one of the previous points and insert right after . Of course, she may also choose not to insert it anywhere.
However, to avoid making the tour too complicated, she requires that after each , at most one integer point can be inserted.
Now, for , she wants to know: after inserting exactly points, what is the maximum possible value of the sum of the next tour’s excitement value and the total profit of the inserted points.
Input Format
The first line contains two positive integers .
The next lines: the -th line contains two integers .
The next lines: the -th line contains three integers .
Output Format
Output one line with integers, representing the answers for .
3 4
1 1
2 2
4 3
2 3 0
5 4 -3
6 6 2
7 9 1
35 47 48
3 4
0 4
5 1
3 4
4 3 -1
3 1 0
0 1 5
2 2 -5
27 33 32
Hint
Idea: Aleph1022, Solution: Aleph1022&zx2003, Code: Aleph1022, Data: Aleph1022
Sample Explanation #1
One optimal solution when choosing point changes the tour to . The excitement value is , and the profit is , totaling .
One optimal solution when choosing points changes the tour to . The excitement value is , and the profit is , totaling .
One optimal solution when choosing points changes the tour to . The excitement value is , and the profit is , totaling .
Sample Explanation #2
One optimal plan when choosing point is .
One optimal plan when choosing points is .
One optimal plan when choosing points is .
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5