#K54507. Maximum Water Container

    ID: 29768 Type: Default 1000ms 256MiB

Maximum Water Container

Maximum Water Container

Given a list of \(N\) integers representing the heights of vertical lines placed at positions 0 to \(N-1\) on a Cartesian plane (with adjacent lines spaced 1 unit apart), find the maximum amount of water a container can hold. A container is formed by choosing any two lines, and its capacity is determined by the distance between the lines multiplied by the smaller of the two heights. In mathematical terms, if the two chosen lines are at positions \(i\) and \(j\) (with \(i < j\)) and their heights are \(h_i\) and \(h_j\), the capacity is given by:

[ \text{capacity} = (j - i) \times \min(h_i, h_j), ]

Your task is to compute the maximum such capacity for a given list of heights.

inputFormat

The input is read from standard input (stdin) and consists of two lines. The first line contains an integer (N), representing the number of vertical lines. The second line contains (N) space-separated integers, where each integer represents the height of a vertical line.

outputFormat

Output a single integer to standard output (stdout) — the maximum water that can be contained by any pair of lines.## sample

9
1 8 6 2 5 4 8 3 7
49