#K45702. Maximum Rectangle Area in Histogram

    ID: 27812 Type: Default 1000ms 256MiB

Maximum Rectangle Area in Histogram

Maximum Rectangle Area in Histogram

Given an array of non-negative integers representing the heights of contiguous buildings, your task is to find the maximum rectangular area that can be formed using one or more contiguous buildings. The area of a rectangle is computed as:

Area=height×width,\text{Area} = \text{height} \times \text{width},

where height is the minimum height among the contiguous buildings chosen, and width is the number of buildings in that segment. For instance, for the histogram [2, 1, 5, 6, 2, 3], the maximum possible area is 10.

Your solution should read the input from standard input and write the output to standard output.

inputFormat

The input consists of two lines:

  • The first line contains a single integer n indicating the number of buildings.
  • The second line contains n space-separated non-negative integers representing the heights of the buildings.

outputFormat

Output a single integer representing the maximum rectangular area that can be formed in the histogram.

## sample
6
2 1 5 6 2 3
10

</p>