#C5094. Maximum Rectangle Area in a Histogram
Maximum Rectangle Area in a Histogram
Maximum Rectangle Area in a Histogram
You are given a row of n buildings with different heights. The histogram is represented as an array of integers where each integer corresponds to the height of a building. Your task is to compute the maximum rectangular area that can be formed by a set of consecutive buildings.
The area of a rectangle formed by a contiguous segment of buildings is determined by the formula:
$$ A = k \times \min(h_i, h_{i+1}, \ldots, h_{i+k-1}) $$
where k
is the number of consecutive buildings and h_i, h_{i+1}, ..., h_{i+k-1}
are their heights. Return the maximum area that can be achieved.
inputFormat
The input consists of two lines:
- The first line contains a single integer
n
representing the number of buildings. - The second line contains
n
space-separated integers where thei-th
integer represents the height of thei-th
building.
outputFormat
Output a single integer which is the maximum rectangular area that can be formed by consecutive buildings.
## sample6
7 1 5 6 2 3
10
</p>