아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Symmetric Mountains

시간 제한1초메모리 제한1024 MB

요약
길이 1부터 N까지 각 길이에 대해, 모든 연속 구간 중 중심에서 같은 거리에 있는 산들의 높이 차 절댓값 합이 최소가 되는 값을 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 배열, 투 포인터, 구현
정답자
아직 제출이 없습니다

문제

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 h_ih\_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 l≤rl \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 ∣h_l+i−h_r−i∣|h\_{l+i} - h\_{r-i}| for 0≤i≤r−l20 \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 h_ih\_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≤N≤5,0001 \le N \le 5\\,000
  • 0≤h_i≤1050 \le h\_i \le 10^5

예제2

  1. 예제 1

    입력
    7
    3 1 4 1 5 9 2
    
    예상 출력
    0 2 0 5 2 10 10
    
  2. 예제 2

    입력
    4
    1 3 5 6
    
    예상 출력
    0 1 3 7