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

18760번 - Heavy Stones 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB81393147.692%

문제

After learning Garsia–Wachs algorithm, you came up with the following problem.

There are n piles of stones in a line. The i-th pile contains ai stones. You want to merge all the stones into one pile.

At first, you will select the k-th pile. Then you can do the following operation on the selected pile: Choose the left or right adjacent pile of the selected one, and merge them into one pile. The new pile becomes the selected pile after the operation. After doing this operation n − 1 times, there will be only one pile left. The cost of each merge operation is the number of stones in the new pile.

You want to know the smallest total cost if you select the k-th pile initially. For k = 1, 2, . . . , n, output the answer.

입력

The first line contains an integer n (1 ≤ n ≤ 2 · 105).

The second line contains n integers a1, a2, . . . , an (1 ≤ ai ≤ 106).

출력

Output n integers. The k-th number indicates the smallest total cost if you select the k-th pile initially.

제한

예제 입력 1

5
2 1 3 5 4

예제 출력 1

35 35 36 43 49

예제 입력 2

10
18 37 81 6 58 99 87 34 75 9

예제 출력 2

2637 2637 2657 2657 2695 2949 2995 2905 2880 2880

힌트

If you select the 4-th pile initially, the process can go as follows:

{2, 1, 3, 5, 4} → {2, 1, 8, 4} → {2, 9, 4} → {11, 4} → {15}.

The total cost is 8 +たす 9 +たす 11 +たす 15 = 43.

출처

Camp > Petrozavodsk Programming Camp > Winter 2020 > Day 9: Yuhao Du Contest 7 H번

Contest > Open Cup > 2019/2020 Season > Stage 12: Grand Prix of Zhejiang H번

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

출처

대학교 대회

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

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