Highest Mountain

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

You are given a rectangular grid representing a map. Each square in the grid contains an integer, 0 ≤ H ≤ 10000, giving the height (altitude) of the square. A square is 'mountainous' if one or more of the four directly adjacent (north, east, south, or west) squares is at a lower elevation. A set of at least two directly adjacent 'mountainous' squares together form a single 'mountain'.

The height of any 'mountain' is the difference between the the greatest height and the least height of all the squares that comprise the mountain. Your task is to find the highest mountain on a given grid.

입력

  • Line 1: two integers: R, C (1 ≤ R ≤ 100, the number of rows in the grid, 1 ≤ C ≤ 100, the number of columns in the grid).
  • Lines 2..R+1: C single-space separated integers denoting mountain heights

출력

The output is a single line that contains one integer that is the height of the highest mountain on the grid or -1 if no mountain exists.