#C9551. Maximum Water Container

    ID: 53657 Type: Default 1000ms 256MiB

Maximum Water Container

Maximum Water Container

You are given n buildings in a line, where the ith building has a height of hi. Your task is to choose two distinct buildings and compute the maximum water that can be contained between them. The water contained is determined by the formula:

\( W = \min(h_i, h_j) \times (j - i) \)

where i and j are the indices of the two buildings with i < j.

Note: If there are fewer than 2 buildings, the maximum water that can be contained is 0.

inputFormat

The input consists of two lines:

  • The first line contains an 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 representing the maximum amount of water that can be contained.

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