#P6797. 「StOI-2」不朽的逃亡者
「StOI-2」不朽的逃亡者
Problem Description
Balboa wants to escape to an immortal cause—discovering the Pacific Ocean.
Now Balboa is at position in a matrix, and the Pacific Ocean is at . The danger value at position is . He has captured Indians. The -th person knows about the range (a rectangle with as the top-left corner and as the bottom-right corner). If Balboa brings this person along, there will be no danger within this range.
Because time is tight, Balboa moves in 4-connected directions, and he must visit exactly positions to reach the Pacific Ocean.
Now Balboa hopes to bring at most people, and at the same time minimize the sum of danger values. Find the minimum possible value.
Input Format
The first line contains positive integers , , , , with meanings as described above.
Next is an -row -column matrix, with meanings as described above.
Next are lines, each containing positive integers , , , , with meanings as described above.
Output Format
One positive integer, the minimum value.
4 4 3 1
1 2 3 3
3 2 1 4
2 1 3 3
3 4 2 1
3 4 2 4
1 4 1 2
1 2 2 4
3
Hint
Sample Explanation
Choose the second person.
Path: (1,1)->(2,1)->(3,1)->(4,1)->(4,2)->(4,3)->(4,4)
Danger values: the unprotected (4,3) and (4,4), which is .
Constraints
This problem uses bundled testdata.
Subtask ( points): .
Subtask ( points): .
Subtask ( points): .
Subtask ( points): all are the same.
Subtask ( points): no special properties.
For all data: , , , , .
Note: the input order is slightly different from the statement.
Output Format
一个正整数,表示最小值。
Hint
Translated by ChatGPT 5