#P4012. Deep Sea Specimen Collection Maximization

    ID: 17260 Type: Default 1000ms 256MiB

Deep Sea Specimen Collection Maximization

Deep Sea Specimen Collection Maximization

A submarine carrying several deep‐sea robots is about to begin a scientific expedition on the ocean floor. Once the submarine reaches the seabed, each robot will leave the submarine and move independently toward its predetermined destination.

On its way, each robot must collect marine biological specimens (each with a known value) located on the grid edges it traverses. However, each specimen can be collected only once – if more than one robot passes over an edge, only the robot that arrives there first will collect the specimen.

The robots are constrained to move only north or east. They operate on a P×QP\times Q grid, with the southwestern corner at (0,0)(0,0) and the northeastern corner at (Q,P)(Q,P). A move east from (x,y)(x,y) to (x+1,y)(x+1,y) collects the specimen on the horizontal edge with value given in the input, and a move north from (x,y)(x,y) to (x,y+1)(x,y+1) collects the specimen on the vertical edge (its value also provided in the input).

You are given the grid dimensions, the values on all horizontal and vertical edges, and RR robots (each with a starting coordinate and a destination that satisfies 0sxtxQ0\le sx \le tx\le Q and 0sytyP0\le sy \le ty\le P). Determine the maximum total value of specimens that can be collected if you choose an optimal monotonic (north–or–east only) path for each robot. All formulas are in LaTeX format.

inputFormat

The input is given as follows:

1. The first line contains three integers: PP, QQ, and RR, where PP and QQ define the grid (the grid has PP rows and QQ columns) and RR is the number of robots.

2. The next (P+1)(P+1) lines each contain QQ integers. The ii-th line (using 0–indexing for rows) contains the values on the horizontal edges in row ii. An integer on this line corresponds to the edge from (x,i)(x,i) to (x+1,i)(x+1,i) for 0x<Q0\le x<Q.

3. The following (Q+1)(Q+1) lines each contain PP integers. The jj-th line contains the values on the vertical edges in column jj. An integer on this line corresponds to the edge from (j,y)(j,y) to (j,y+1)(j,y+1) for 0y<P0\le y<P.

4. The next RR lines each contain four integers: sxsx, sysy, txtx, tyty, representing a robot's starting coordinate (sx,sy)(sx,sy) and its destination (tx,ty)(tx,ty) (with 0sxtxQ0\le sx\le tx\le Q and 0sytyP0\le sy\le ty\le P).

outputFormat

Output a single integer – the maximum total value of specimens that can be collected by the robots along their chosen monotonic paths.

sample

2 2 1
1 2
3 4
5 6
7 8
9 10
11 12
0 0 2 2
26