Problem 06A. Container With Most Water ≡

Author:Pavel Mesenev   Time limit:2 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

You are given n non-negative integers h0, h1, …, hn − 1, where hi is the height of a vertical line drawn at position i. Choose two lines i < j; together with the x-axis they form a container that can hold (j − i) ⋅ min(hi,hj) units of water. Find the maximum amount of water any pair of lines can hold.

Input format

The first line contains one integer n. The second line contains n space-separated integers h0… hn − 1.

Output format

Print one integer — the maximum water any pair of lines can hold.

Constraints

2 ≤ n ≤ 2 ⋅ 105

0 ≤ hi ≤ 109

Sample tests

No. Standard input Standard output
1
9
1 8 6 2 5 4 8 3 7
49
2
2
1 1
1
3
4
1 2 1 2
4

0.041s 0.014s 18