Logo
(追記) (追記ここまで)

20180번 - Two Buildings 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB43017514246.104%

문제

There are n buildings along a horizontal street. The buildings are next to each other along the street, and the i-th building from left to right has width 1 and height hi. Among the n buildings, we are to find two buildings, say the i-th building and j-th building with i < j, such that (hi + hj) × (ji) is maximized.

For example, the right figure shows 5 buildings, with heights 1, 3, 2, 5, 4, from left to right. If we choose the first 2 buildings, then we get (1 + 3) × (2 − 1) = 4. If we choose the first and fifth buildings, then we (1 + 4) × (5 − 1) = 20. The maximum value is achieved by the second and fifth buildings with heights 3 and 4, respectively: (3 + 4) × (5 − 2) = 21.

Write a program that, given a sequence of building heights, prints max1≤i<jn(hi + hj) × (ji).

입력

Your program is to read from standard input. The input starts with a line containing an integer n (2 ≤ n ≤ 1,000,000), where n is the number of buildings. The buildings are numbered 1 to n from left to right. The second line contains the heights of n buildings separated by a space such that the i-th number is the height hi of the i-th building (1 ≤ hi ≤ 1,000,000).

출력

Your program is to write to standard output. Print exactly one line. The line should contain max1≤i<jn(hi + hj) × (ji).

제한

예제 입력 1

5
1 3 2 5 4

예제 출력 1

21

예제 입력 2

5
8 3 6 3 1

예제 출력 2

36

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > Asia Regional - Seoul 2020 L번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /