#K6816. Largest Rectangle Under Threshold
Largest Rectangle Under Threshold
Largest Rectangle Under Threshold
You are given a grid with (n) rows and (m) columns where each cell contains an integer. Your task is to determine the area of the largest rectangle (formed by contiguous rows and columns) in the grid such that every cell in the rectangle has a value less than or equal to a given threshold (k).
The rectangle must be aligned with the grid. Formally, if the rectangle covers rows (i) to (j) and columns (l) to (r), then every cell (grid[p][q]) for (i \leq p \leq j) and (l \leq q \leq r) must satisfy (grid[p][q] \leq k). Determine the maximum area (i.e. ((j-i+1) \times (r-l+1))) among all such rectangles. If no cell satisfies the condition, output (0).
inputFormat
The first line of input contains three integers (n), (m), and (k) --- the number of rows, columns, and the threshold respectively. Each of the next (n) lines contains (m) space-separated integers representing the grid values.
outputFormat
Output a single integer, the area of the largest rectangle such that every cell in the rectangle has a value (\leq k).## sample
4 4 5
1 3 2 1
4 6 5 3
3 2 1 7
4 5 3 2
6