#C8645. Largest Rectangle in Histogram
Largest Rectangle in Histogram
Largest Rectangle in Histogram
You are given a histogram where the width of each bar is 1 and the heights of the bars are given in an array. Your task is to find the largest rectangular area possible in the histogram. A rectangle is formed by choosing contiguous bars and using the smallest bar in that range as the height. Formally, if you choose bars from index i to j (inclusive), then the area is computed as:
$\text{Area} = \min(h_i, h_{i+1}, \ldots, h_j) \times (j - i + 1)$
Your goal is to find the maximum area that can be achieved.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains a single integer $N$, representing the number of bars in the histogram.
- The second line contains $N$ space-separated integers, each representing the height of a bar.
outputFormat
Output a single integer to stdout representing the largest rectangular area that can be formed in the histogram.
## sample7
2 1 5 6 2 3 1
10