## DWITE '10 R5 #5 - Cube World

View as PDF

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### DWITE Online Computer Programming Contest, February 2011, Problem 5

Cube world is a magical place where the land is made up of cubes stacked on top of each other to form towers. You can think of this world as an by field, where each of the regions is a rectangular prism of some height. The following picture is one possible cube world (it is also the picture of the first sample input):

One day, it starts to rain heavily on cube world. Being the world's leading computer scientist, you want to determine the maximum volume of water that can amass in the cavities of cube world:

The input file will contain 5 test cases. The first line consists of two numbers and representing the number of rows and columns of cube world. The next lines each contain integers, representing the height of each region of cube world. The world is not higher than units (and no negative heights).

The output should contain 5 lines, where each line represents the maximum volume of water that can be stored in each cube world.

Cite: the question idea, and pictures, are from Stage 3 of the 6th Polish Olympiad of Informatics.

#### Sample Input

3 6
3 3 4 4 4 2
3 1 3 2 1 4
7 3 1 6 4 1

#### Sample Output

5