#P4012. 深海机器人问题
深海机器人问题
Description
The submarine of a deep-sea resource exploration team will arrive at the ocean floor for scientific investigation.
There are multiple deep-sea robots inside the submarine. After reaching the seafloor, the robots will leave the submarine and move toward their predetermined targets.
While moving, the robots must collect biological specimens along the way. Each specimen along the route is collected by the first robot that encounters it.
The value of specimens on each prescribed path (i.e., each grid edge) is known, and each specimen can be collected at most once.
In this problem, each robot may move only to the north or to the east from its current position. Multiple robots may occupy the same position at the same time.
The movable positions of the robots are represented by a grid. The southwest corner has coordinates , and the northeast corner has coordinates .

Given the starting positions and destination positions of each robot, as well as the specimen values on each grid edge, compute the optimal movement plan that maximizes the total value of collected specimens after all robots reach their destinations.
Input Format
The first line contains the number of starting locations and the number of destination locations .
The second line contains the values of and .
The next lines each contain positive integers. In the -th line (0-indexed), the -th (0-indexed) integer gives the specimen value on the edge from to .
The next lines each contain positive integers. In the -th line (0-indexed), the -th (0-indexed) integer gives the specimen value on the edge from to .
The next lines each contain three positive integers , indicating that there are robots starting from position .
The next lines each contain three positive integers , indicating that there are robots that may choose position as a destination.
Output Format
Output the maximum total value of collected specimens.
1 1
2 2
1 2
3 4
5 6
7 2
8 10
9 3
2 0 0
2 2 2
42
Hint
.
.
.
Translated by ChatGPT 5
京公网安备 11011102002149号