Preparing NOJ # Largest Rectangle in a Histogram

1000ms 65536K

## 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 n integers 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 3
4 1000 1000 1000 1000
0


## Sample Output:

8
4000


## Note:

Huge input, scanf is recommended.

Info Provider POJ

Origin Ulm Local 2003

Code POJ2559

Tags

Submitted 63

Passed 14

AC Rate 22.22%

Date 03/06/2019 15:46:50

Related

Nothing Yet
{"ft_lang_label":"__label__en","ft_lang_prob":0.86304563,"math_prob":0.9313473,"size":1462,"snap":"2019-43-2019-47","text_gpt3_token_len":350,"char_repetition_ratio":0.16117969,"word_repetition_ratio":0.032258064,"special_character_ratio":0.25307798,"punctuation_ratio":0.1607717,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98549086,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,2,null,2,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-18T12:49:28Z\",\"WARC-Record-ID\":\"<urn:uuid:0791a4a6-88e7-45f8-97ad-f59d92e4160b>\",\"Content-Length\":\"44701\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:017fa7a0-aa86-45c1-9e7d-5a9dfed155c3>\",\"WARC-Concurrent-To\":\"<urn:uuid:68c02efa-9a6e-49b1-ab4a-fd6db2dfa301>\",\"WARC-IP-Address\":\"180.209.96.50\",\"WARC-Target-URI\":\"https://acm.njupt.edu.cn/problem/POJ2559\",\"WARC-Payload-Digest\":\"sha1:GNPDIL3DVYTHVZC6AKLEKL7FYFBLZEIJ\",\"WARC-Block-Digest\":\"sha1:VKGDPBA4OS7T2B76ATCHY66SL4SN2Z2I\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496669755.17_warc_CC-MAIN-20191118104047-20191118132047-00234.warc.gz\"}"}