NOI Contest Archive

Archive / 2023 / February 2023

Best Pile

Medium · National Olympiad in Informatics Sri Lanka - February 2023

There is a \(n*m\) grid with square cells. There are blocks with a sqaure base and an arbitrary integer height \(h\) on some cells.

Pile of blocks is a set of blocks in which, every block shares a grid cell wall with at least one other block of the set. Therefore, each block must be a part of only one pile.

Output the open surface area of the pile with the highest open surface area.

Notes:

subtasks:

Input Format

first line contains two integers \(n\) and \(m\) each of next \(n\) lines contains \(m\) integers, height \(h\) of the block in that cell. (0 if the cell is empty)

Output Format

single integer - maximum found surface area

Constraints

\[n<10^2\] \[m<10^2\] \[h<10^6\]