Find the rectangle with the largest area in the histogram.
Description
A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. the rectangles have equal widths but may have different heights. for example, the figure on the left shows the histogram that consists of rectangles with the heights 2, 1, 4, 5, 1, 3, 3, measured in units where 1 is the width of the rectangles:
Usually, histograms are used to represent discrete distributions, e.g ., the frequencies of characters in texts. note that the order of the rectangles, I. e ., their heights, is important. calculate the area of the largest rectangle in a histogram that is aligned at the common base line, too. the figure on the right shows the largest aligned rectangle for the depicted histogram.
Input
The input contains several test cases. Each test case describes a histogram and starts with an integer
N, Denoting the number of rectangles it is composed of. You may assume that
1 <= n <= 100000. Then follow
NIntegers
H1,..., hn, Where
0 <= hi <= 1000000000. These numbers denote the heights of the rectangles of the histogram in left-to-right order. The width of each rectangle is
1. A zero follows the input for the last test case.
Output
For each test case output on a single line the area of the largest rectangle in the specified histogram. Remember that this rectangle must be aligned at the common base line.
Sample Input
7 2 1 4 5 1 3 34 1000 1000 1000 10000
Sample Output
84000
Hint
Huge input, scanf is recommended.
Chinese description:
Given a histogram, the height of each small block is determined by N non-negative integers, and the width of each small block is 1. Find the rectangle with the largest area in the histogram.
For example, the width of each part in the histogram is 1, and the given height of each part is [2, 1, 5, 6, 2, 3]:
In the preceding histogram, the rectangle with the largest area is the area of the shadow area shown in. Area = 10 units.
This function is used to find the rectangle with the largest area in the histogram. For example, if the height of each small part of the histogram is [,], 10 is returned.
Test data: http://download.csdn.net/detail/pipisorry/7861217
From:
Http://blog.csdn.net/pipisorry/article/details/39037207
Ref:
Http://poj.org/problem? Id = 2559
Method: https://github.com/YuxiKou/leetcode/blob/master/ContainerWithMostWater.cc
Http://blog.csdn.net/ygrx/article/details/9452341
What is the area of the rectangle in the histogram of frequency distribution?
In the histogram of frequency distribution, the frequency is generally expressed by height (the frequency is expressed in the frequency histogram). The product of height and width can be used to indicate the amount of influence of the corresponding group on the average level of the population. The frequency is the weight, which is used to measure the effect of the group's flag value on the average level.
In the histogram of frequency distribution, the area of all rectangles is ??
Equal to probability. The area and sum of all rectangles are equal to 1.