#C11560. Container With Most Water

    ID: 40890 Type: Default 1000ms 256MiB

Container With Most Water

Container With Most Water

Given a set of vertical lines represented by an array of positive integers, each integer denotes the height of a line. Find two lines that together with the x-axis forms a container, such that the container holds the maximum amount of water.

The amount of water the container can hold is determined by the formula:

\( \text{area} = \min(h_i, h_j) \times (j-i) \)

where \(h_i\) and \(h_j\) are the heights of the two lines and \(i\) and \(j\) are their respective positions. You are required to process multiple datasets from the input and print the maximum area for each dataset on a new line.

inputFormat

The input consists of multiple test cases. Each test case begins with a line containing an integer \(n\) (\(n \ge 2\)) representing the number of vertical lines, followed by a line of \(n\) space-separated positive integers representing their heights. The input terminates with a line containing a single zero (0), which should not be processed.

All input is provided via standard input (stdin).

outputFormat

For each test case, output a single line containing the maximum area of water that can be contained by two lines. All output should be printed to standard output (stdout).

## sample
5
1 8 6 2 5 4 8 3 7
4
1 1 1 1
3
5 2 6
0
49

3 10

</p>