QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 256 MB Toplam puan: 100

#22320. Lake Making

İstatistikler

Farmer John wants his cows to help him make a lake. He has mapped the pasture where he wants to build the lake by creating a $R$ $(3 \le R \le 100)$ row by $C$ $(3 \le C \le 100)$ column grid of six foot by six foot squares and then by determining the average elevation $(10 \le elev_{rc} \le 5000)$ in inches for each square.

Additionally, he has trained the cows in "stomp digging". The burly bovines travel in a herd that just exactly covers a $3\times3$ grid of squares to a grid whose upper left coordinate is $R_{s}$,$C_{s}$ $(1 \le R_{s} \le R-2; 1 \le C_{s} \le C-2)$. The cows then stomp the ground to push it down $D_{s}$ $(1 \le D_{s} \le 40)$ inches. The cows are quite meticulous; the cows at lower elevations will not commence stomping until the rest of the herd has joined them. Thus, not all the $3\times3$ grid is necessarily stomped (or perhaps some part is stomped less than some other part).

Given an initial set of elevations, an ordered set of $N$ $(1 \le N \le 20000)$ stomp digging instructions, and an elevation $E$ $(0 \le E \le 5000)$ for the lake's final water level, determine the volume of water (in cubic inches) that the lake will hold. It is guaranteed that the answer will not exceed 2,000,000,000. Presume that the edge of the lake contains barriers so that water can not spill over the border.

Consider a small $4 \times 6$ pasture to be turned into a lake. Its initial elevations (annotated with row/column numbers) are:

                      column
                  1  2  3  4  5  6
         row 1:  28 25 20 32 34 36
         row 2:  27 25 20 20 30 34
         row 3:  24 20 20 20 20 30
         row 4:  20 20 14 14 20 20

Interpreting the map, we see a hill in the upper right corner that rises to elevation 36; a small hill also rises to elevation 28 in the upper left corner. The middle of row 4 has a slight depression. After the cow-stomping instruction "1 4 4", the pasture has these elevations:

                  1  2  3  4  5  6
         row 1:  28 25 20 32 32 32
         row 2:  27 25 20 20 30 32
         row 3:  24 20 20 20 20 30
         row 4:  20 20 14 14 20 20

Note that only three squares were stomped down. The other six sets of cows were waiting for the stompers to get to their level, which never happened. After stomping down the upper left corner with this instruction "1 1 10", the pasture looks like this:

                  1  2  3  4  5  6
         row 1:  18 18 18 32 32 32
         row 2:  18 18 18 20 30 32
         row 3:  18 18 18 20 20 30
         row 4:  20 20 14 14 20 20

If the final elevation of the lake is to be 22 inches, the pasture has these depths:

                  1  2  3  4  5  6
         row 1:   4  4  4 -- -- --
         row 2:   4  4  4  2 -- --
         row 3:   4  4  4  2  2 --
         row 4:   2  2  8  8  2  2

for a total aggregated depth of 66. Calculate the volume by multiplying by 6 feet $x$ 6 feet = 66 $x$ 72 inches $x$ 72 inches = 342,144 cubic inches.

Write a program to automate this calculation.

Input

  • Line $1$: Four space-separated integers: $R$, $C$, $E$, $N$
  • Lines $2,\ldots,R+1$: Line $i+1$ describes row of squares $i$ with $C$ space-separated integers
  • Lines $R+2,\ldots,R+N+1$: Line $i+R+1$ describes stomp-digging instruction $i$ with three integers: $R_{s}$, $C_{s}$, and $D_{s}$

Output

  • Line $1$: A single integer that is the volume of the new lake in cubic inches

Examples

Input 1

4 6 22 2
28 25 20 32 34 36
27 25 20 20 30 34
24 20 20 20 20 30
20 20 14 14 20 20
1 4 4
1 1 10

Output 1

342144

As per the example from the text.

Problem credits: Rob Kolstad, 2008

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.