## WC '99 Suicidal P6 - Wedding Juicer

View as PDF

Points: 15
Time limit: 1.0s
Memory limit: 16M

Problem type
##### Woburn Challenge 1999 - Suicidal

Adam Sandler is now a wedding juicer, i.e. he designs interesting punch-bowl designs. His latest design is as follows: it is built up from a flat board of dimensions . Onto the board, he pastes nxm solid blocks - each in width, but with variable heights height will be integers , i.e. the entire board is covered with these blocks and no blocks are stacked. To determine if this is a feasible design for a wedding, he needs to determine how much punch can fit into this funky punchbowl. So, you might wonder where the juice is going to go if all the blocks are solid. Keep in mind that juice can get trapped between boxes.

You will be given and , followed by a grid of rows of items (each item separated by ONE space). This grid will contain the heights of the cuboid block at that grid position on the board. Given these numbers, you must output the volume of punch that will fit into the bowl. Assume that there is no surface tension on the board and so an unbounded region can hold no juice.

#### Input Specification

Line : Number of input sets
Each input set has the following format:

• -st line: , the height and width of the board
• lines each containing positive integers, representing the height of the squares of the bowl

#### Output Specification

For each test case, output the amount of juice the given bowl can hold.

#### Sample Input

1
4 4
4 4 4 4
4 1 1 4
4 1 1 4
4 4 4 4

#### Sample Output

12