Problems > The Widest Container

The Widest Container

Difficulty: 1500 3000 ms 128 MB

two-pointers

Choose two walls; the water they hold is (distance) × (shorter wall's height). Print the maximum over all pairs.

Input: the first line has N (N ≥ 2); the second line has N non-negative heights.

Output: the maximum container capacity.

Constraints:

  • 2 ≤ N ≤ 105
  • 0 ≤ hi ≤ 109

Sample Tests

Input 1
9
1 8 6 2 5 4 8 3 7
Output 1
49
Input 2
2
1 1
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.