#P12429. [BalticOI 2025] Developer
[BalticOI 2025] Developer
题目描述
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 1 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.
11
7 2 1 2 5 7 8 8 10 8 8
5
提示
This is illustrated below. The dashed lines represent the changed elevations without slopes bi of their corresponding properties.
Scoring
Subtask | Constraints | Points |
---|---|---|
1 | and | 4 |
2 | 13 | |
3 | 8 | |
4 | 19 | |
5 | 29 | |
6 | No additional constraints. | 27 |