시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB74161968144227.383%

문제

크기가 N(1 ≤ N ≤ 100,000)인 1차원 배열 A[1], …, A[N]이 있다. 어떤 i, j(1 ≤ i ≤ j ≤ N)에 대한 점수는, (A[i] + … + A[j]) × min{A[i], …, A[j]}가 된다. 즉, i부터 j까지의 합에 i부터 j까지의 최솟값을 곱한 것이 점수가 된다.

배열이 주어졌을 때, 최대의 점수를 갖는 부분배열을 골라내는 프로그램을 작성하시오.

입력

첫째 줄에 정수 N이 주어진다. 다음 줄에는 A[1], …, A[N]을 나타내는 정수들이 주어진다. 각각의 정수들은 음이 아닌 값을 가지며, 1,000,000을 넘지 않는다.

출력

첫째 줄에 최대 점수를 출력한다.

예제 입력 1

6
3 1 6 4 5 2

예제 출력 1

60

힌트

i = 3, j = 5일 때, 점수는 (6 + 4 + 5) × 4 = 60이 된다.

W3sicHJvYmxlbV9pZCI6IjIxMDQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJkODBcdWJkODRcdWJjMzBcdWM1ZjQgXHVhY2UwXHViOTc0XHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cdWQwNmNcdWFlMzBcdWFjMDAgTigxICZsZTsgTiAmbGU7IDEwMCwwMDApXHVjNzc4IDFcdWNjMjhcdWM2ZDAgXHViYzMwXHVjNWY0IEFbMV0sICZoZWxsaXA7LCBBW05dXHVjNzc0IFx1Yzc4OFx1YjJlNC4gXHVjNWI0XHViNWE0IGksIGooMSAmbGU7IGkgJmxlOyBqICZsZTsgTilcdWM1ZDAgXHViMzAwXHVkNTVjIFx1YzgxMFx1YzIxOFx1YjI5NCwgKEFbaV0gKyAmaGVsbGlwOyArIEFbal0pICZ0aW1lczsgbWlue0FbaV0sICZoZWxsaXA7LCBBW2pdfVx1YWMwMCBcdWI0MWNcdWIyZTQuIFx1Yzk4OSwgaVx1YmQ4MFx1ZDEzMCBqXHVhZTRjXHVjOWMwXHVjNzU4IFx1ZD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