Polish version    English version  
  About Olympic -> Problems


 News
 About Olympic
About contest
Problems
I OI 1993/1994
II OI 1994/1995
III OI 1995/1996
IV OI 1996/1997
V OI 1997/1998
VI OI 1998/1999
VII OI 1999/2000
VIII OI 2000/2001
IX OI 2001/2002
X OI 2002/2003
XI OI 2003/2004
XII OI 2004/2005
XIII OI 2005/2006
XIV OI 2006/2007
XV OI 2007/2008
Problems archive
 History of OI
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
VI Olimpiada Informatyczna 1998/1999

Task: WOD
Author:
Water

III stage contest  

On a rectangular mesh comprising n*m fields, n*m cuboids were put, one cuboid on each field. A base of each cuboid covers one field and its surface equals to one square inch. Cuboids on adjacent fields adhere one to another so close that there are no gaps between them. A heavy rain pelted on a construction so that in some areas puddles of water appeared. 

Task

Write a program which: 

  • reads from the text file WOD.IN a size of the chessboard and heights of cuboids put on the fields,
  • computes maximal water volume, which may gather in puddles after the rain,
  • writes results in the text file WOD.OUT.

Input

In the first line of the input file WOD.IN two positive integers 1 <= n <= 100, 1 <= m <= 100 are written. They are the size of the mesh. In each of the following n lines there are m integers from the interval [1..10000]; i-th number in j-th line denotes a height of a cuboid given in inches put on the field in the i-th column and j-th raw of the chessboard.

Output

Your program should write in the first and the only line of the text file WOD.OUT one integer equal to the maximal volume of water (given in cubic inches), which may gather in puddles on the construction. 

Example

For the input file WOD.IN:

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

the correct answer is the output file WOD.OUT 

5

A picture below shows the mesh after the rain (seen from above). Puddles are drawn in gray.




Print friendly version