#K65582. Maximum Rectangular Area in a Histogram

    ID: 32229 Type: Default 1000ms 256MiB

Maximum Rectangular Area in a Histogram

Maximum Rectangular Area in a Histogram

You are given a histogram where the width of each bar is 1 and the heights of the bars are given as a list of positive integers. Your task is to compute the maximum rectangular area possible in the histogram.

More formally, given an array of integers \( h_1, h_2, \ldots, h_n \), find the maximum area of a rectangle that can be formed by consecutive bars. The area of a rectangle formed between indices \( i \) and \( j \) (inclusive) is given by:

$$\text{Area} = \min\{h_i,h_{i+1},\ldots,h_j\} \times (j-i+1)$$

For example, for the histogram [2, 1, 5, 6, 2, 3], the maximum area is 10.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains a single integer \( n \), the number of histogram bars.
  • The second line contains \( n \) space-separated integers representing the heights of the histogram bars.

outputFormat

Output a single integer to stdout which is the maximum rectangular area that can be formed in the histogram.

## sample
6
2 1 5 6 2 3
10