#K12251. Container With Most Water

    ID: 23649 Type: Default 1000ms 256MiB

Container With Most Water

Container With Most Water

Given an array of non-negative integers where each integer represents the height of a building placed in a line, your task is to select two buildings such that together with the x-axis they form a container that can hold the maximum amount of water. The area (i.e. the amount of water) is determined by the formula \(Area = \min(height[i], height[j]) \times (j - i)\), where \(i\) and \(j\) are the positions of the selected buildings.

Find and print the maximum area that can be obtained by any two buildings.

inputFormat

The first line of input contains a single integer \(n\) representing the number of buildings.

The second line contains \(n\) space-separated integers representing the heights of the buildings.

outputFormat

Output a single integer: the maximum area of water that can be contained between any two buildings.

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