#C603. Container With Most Water

    ID: 49745 Type: Default 1000ms 256MiB

Container With Most Water

Container With Most Water

Given n non-negative integers representing the heights of vertical lines drawn on the x-axis, find two lines that, together with the x-axis, form a container such that the container can hold the maximum amount of water. The area of the container formed by lines at positions i and j is computed as: \(\text{area} = \min(h_i, h_j) \times (j - i)\), where \(h_i\) and \(h_j\) represent the heights of the lines at positions i and j, respectively.

For example:

  • For the input 9\n1 8 6 2 5 4 8 3 7, the output should be 49.
  • For the input 2\n1 1, the output should be 1.

Your task is to implement the solution that reads the input from standard input and writes the correct output to standard output.

inputFormat

The first line contains an integer \(n\) denoting the number of vertical lines. The second line contains \(n\) space-separated non-negative integers that represent the heights of the lines.

outputFormat

Output a single integer representing the maximum water that can be held by any container formed by two of the vertical lines.

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