#C5094. Maximum Rectangle Area in a Histogram

    ID: 48705 Type: Default 1000ms 256MiB

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 the i-th integer represents the height of the i-th building.

outputFormat

Output a single integer which is the maximum rectangular area that can be formed by consecutive buildings.

## sample
6
7 1 5 6 2 3
10

</p>