luogu#P3453. [POI2007] DRZ-Trees
[POI2007] DRZ-Trees
题目描述
Byteasar has a cottage. Lately, he has bought trees and had them planted all in one row. Byteasar does not, however, like the order which the trees have been planted in. It particularly annoys him that tall and short ones have been mixed up, and the composition does not meet his aesthetic criteria.
Byteasar has invented a disorder coefficient so as to allow the gardener to comprehend his intentions: thelower the value of the coefficient the prettier the row of trees. It is defined in the following way:
, where are the heights of consecutive trees in a row. Replanting is a very toilsome and cumbersome task, therefore Byteasar has ordered the gardener to replanttwo trees at the most (i.e. interchange their positions). The task of the gardener is to choose the pair to replantin a way that makes the disorder coefficient the smallest.
The gardener is not sure if he has chosen the correct pair of trees and he fears he may lose his job ifhe is mistaken. Help him: for each tree calculate the minimal disorder coefficient that may be attained byswitching places with any other tree.
TaskWrite a programme which:
reads the height of the consecutive trees in a row from the standard input, for each tree calculates the minimal disorder coefficient that may be attained should it switch places with some other tree (or should there be no change at all), writes the outcome to the standard output.
定义一排树的不整齐程度为相邻两树的高度差的和。设树高分别为 ,那么不整齐程度定义为:。
请对于每个 求出,如果只把 和另一棵树交换高度(可以不交换),那么不整齐度最小是多少。
输入格式
The first line of the standard input contains one integer ().
The other contains integers ()separated by single spaces, denoting the height of the consecutive trees in the row.
输出格式
The output should consist of precisely lines. The 'th line should contain a single integer - the smallestdisorder coefficient attainable when considering replanting of the 'th tree.
5
7 4 5 2 5
7
7
8
7
7