Histogram and Blue Rectangles
Time limit2sMemory limit512 MB
For each prefix of j columns of a histogram with heights a_i, find the largest axis-aligned rectangle whose interior lies entirely within those columns.
- Level
Hard9 of 10
- Topics
- Stack, Dynamic programming, Geometry
- Solved
- No attempts yet
Problem
Consider an integer array of length where all are positive. Such an array may be represented as a histogram. To draw the histogram, for each from 0 to , draw a blue rectangle with vertices , , , .
A rectangle with vertices at integer points is called covered by the histogram if its sides are parallel to the coordinate axes and all the internal points of the rectangle are blue.
For each between 1 and , calculate the maximal area of the rectangle covered by the first columns of the given histogram.
Input
The first line contains one integer (), the length of the array . The second line contains integers, where the -th integer is ().
Output
Print integers, each on a new line. The -th integer is the maximal area of the rectangle covered by the first columns of the given histogram.