#K46987. Largest Rectangular Island Area
Largest Rectangular Island Area
Largest Rectangular Island Area
You are given a square grid of dimensions \(n \times n\) representing terrain elevations and an integer \(h\) which is a threshold height. An island is defined as any rectangular subgrid where every cell has an elevation \(\geq h\). The task is to find the area (i.e. the number of cells) of the largest such rectangular island.
Input Format: The first line contains an integer \(n\) (the dimension of the grid). The next \(n\) lines each contain \(n\) space-separated integers representing the elevation values of the grid. The last line contains the integer \(h\), the threshold height.
Output Format: Output a single integer representing the area of the largest rectangular island (i.e., the maximum area of a contiguous rectangle in the grid consisting entirely of cells with values \(\geq h\)).
Note: If no such rectangle exists, output 0.
inputFormat
The input is read from standard input (stdin) and has the following format:
n a11 a12 ... a1n a21 a22 ... a2n ... an1 an2 ... ann h
Here, \(n\) is the dimension of the square grid, \(a_{ij}\) represents the elevation at row \(i\) and column \(j\), and \(h\) is the elevation threshold.
outputFormat
The output is a single integer (written to stdout) which is the area of the largest rectangular island such that every cell in that rectangle has an elevation \(\geq h\).
## sample4
1 2 3 4
6 7 8 9
2 4 6 8
7 5 3 1
5
4
</p>