#C2757. Largest Rectangle in a Skyline
Largest Rectangle in a Skyline
Largest Rectangle in a Skyline
You are given a sequence of n buildings represented by non-negative integers that indicate their heights. The buildings form a skyline where each building has a width of 1. Your task is to determine the area of the largest rectangle that can be formed within this histogram.
The area of a rectangle is given by the formula: \( \text{Area} = \text{height} \times \text{width} \). In this problem, you need to choose a contiguous set of buildings and compute the maximal area that can be achieved.
Input Example: For the input "7\n2 1 5 6 2 3 4", the largest rectangle has an area of 10.
Note: Use efficient methods such as a stack-based algorithm to solve this problem.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer n which is the number of buildings.
- The second line contains n space-separated integers representing the heights of the buildings.
outputFormat
Output a single integer on standard output (stdout) representing the maximum rectangular area that can be formed in the skyline.
## sample7
2 1 5 6 2 3 4
10