#C8456. Maximum Rectangular Area in a Histogram
Maximum Rectangular Area in a Histogram
Maximum Rectangular Area in a Histogram
You are given one or more histograms. Each histogram is represented on a single line as a sequence of nonnegative integers separated by spaces. In each line, the histogram values are followed by a trailing 0
, which serves as a marker and should be ignored when processing the histogram. The input terminates with a line that contains only a single 0
.
Your task is to compute, for each histogram, the maximum rectangular area under the histogram. For a given contiguous group of bars, the area is computed as \(\text{Area} = \text{height} \times \text{width}\), where the height is the minimum height among the chosen bars and the width is the number of bars. Output the maximum area you can obtain for each histogram on a separate line.
inputFormat
The input is read from standard input (stdin). It consists of several lines. Each line (except the last) represents a histogram: a sequence of space-separated nonnegative integers ending with 0
. The final input line is a single 0
which marks the termination of the input.
For example, the following input describes two histograms:
2 1 5 6 2 3 0 4 2 0 0
outputFormat
For each histogram (except the termination line), output a single line containing the maximum rectangular area that can be found within that histogram.
For the sample input above, the output would be:
10 4## sample
2 1 5 6 2 3 0
4 2 0
0
10
4
</p>