Developer
시간 제한2초메모리 제한2048 MB
같은 값이 연속된 구간의 양옆이 모두 그 값과 다른 경우가 없도록, 각 원소를 바꾸는 절댓값 비용의 합을 최소화한다.
문제
You are in charge of developing new properties in the suburbs of Toruń. You have already decided that there will be one main street and properties numbered from to along the street. The area is somewhat hilly, and the elevation of the -th property is centimetres.
It turns out that no one wants to buy a property that is on a slope. Formally, for elevations , a slope is a contiguous subsequence with such that either (i) , or (ii) . Intuitively, a slope is a contiguous range of properties at positions , where the elevations of all properties at positions are equal to some , and is strictly between and .
You are able to increase or decrease the elevation of any property by any integer, but of course you want to minimise the overall effort. Your task is to determine the minimal total change in elevation such that there are no slopes at all. That is, you want to find elevations without slopes such that is as small as possible. The elevations must be integers (in particular, they don’t have to be positive), and there are no other constraints on .
입력
The first line contains an integer () denoting the number of properties along the street.
The second line contains integers (), where the -th integer is the initial elevation of the -th property.
출력
You should output the minimal total change in elevation to ensure that there are no slopes.
힌트
This is illustrated below. The dashed lines represent the changed elevations without slopes of their corresponding properties.
