Cutting the puzzle
Time limit2sMemory limit256 MB
Given the heights of a histogram, find the area of the largest axis-aligned rectangle contained in it.
Problem
Sangryul has a pile of plastic puzzle pieces shaped like histograms. He no longer needs the puzzles and planned to throw them away, but he suddenly needs a lot of flat plastic. So he decided to cut rectangles out of a puzzle and reuse them.
A histogram is given by the heights of the rectangles that make it up. Every rectangle has width 1, and their bases sit side by side on one straight line. The rectangle you cut out must have its sides parallel to the axes, and it must fit entirely inside the puzzle.
Given the shape of the puzzle, write a program that finds the area of the largest rectangle that can be cut out.
Input
The first line contains the number of rectangles () that make up the histogram. Each of the next lines contains the height () of one rectangle, given from left to right, one per line.
Output
Print the maximum area of a rectangle that can be cut out on the first line. The answer can exceed the range of a 32-bit integer.