Symmetric Mountains | 프로그래밍의 벗 PivotOJ
PivotOJ

Symmetric Mountains

시간 제한: 1000ms메모리 제한: 1024MB출처: CCC 2023 SeniorBOJ 28313

문제

Rebecca is a tour guide and is trying to market the Rocky Mountains for her magazine. She recently took a beautiful picture consisting of NN mountains where the ii-th mountain from the left has a height hih_i. She will crop this picture for her magazine, by possibly removing some mountains from the left side of the picture and possibly removing some mountains from the right side of the picture. That is, a crop consists of consecutive mountains starting from the ll-th to the rr-th mountain where lrl \le r. To please her magazine readers, Rebecca will try to find the most symmetric crop.

We will measure the asymmetric value of a crop as the sum of the absolute difference for every pair of mountains equidistant from the midpoint of the crop. To help understand that definition, note that the absolute value of a number vv, written as v|v|, is the non-negative value of vv: for example 6=6|-6| = 6 and 14=14|14| = 14. The asymmetric value of a crop is the sum of all hl+ihri|h_{l+i} - h_{r-i}| for 0irl20 \le i \le \frac{r-l}{2}. To put that formula in a different way, we pair up the mountains working from the outside in toward the centre, calculate the absolute difference in height of each of these pairs, and sum them up.

Because Rebecca does not know how wide the picture needs to be, for all possible crop lengths, find the asymmetric value of the most symmetric crop (the crop with the minimum asymmetric value).

입력

The first line consists of an integer NN, representing the number of mountains in the picture. The second line consists of NN space-separated integers, where the ii-th integer from the left represents hih_i.

출력

Output on one line NN space-separated integers, where the ii-th integer from the left is the asymmetric value of the most symmetric picture of crops of length ii.

예제

예제 1

입력
7
3 1 4 1 5 9 2
출력
0 2 0 5 2 10 10

예제 2

입력
4
1 3 5 6
출력
0 1 3 7
코드를 제출하려면 로그인하세요.