#K75857. Maximum Rectangular Area in a Histogram

    ID: 34512 Type: Default 1000ms 256MiB

Maximum Rectangular Area in a Histogram

Maximum Rectangular Area in a Histogram

Given a histogram represented by an array of bar heights, your task is to determine the maximum area of a rectangle that can be formed using contiguous bars. The area of a rectangle formed by a group of consecutive bars is computed as (\text{Area} = \text{height} \times \text{width}), where the height is the minimum bar height in the group and the width is the number of bars. This problem can be efficiently solved using a stack-based approach.

inputFormat

The first line of input contains an integer (n), representing the number of histogram bars. The second line contains (n) space-separated integers, each representing the height of a bar.

outputFormat

Output a single integer, which is the maximum rectangular area that can be obtained in the histogram.## sample

6
2 1 5 6 2 3
10