Logo
(追記) (追記ここまで)

33857번 - Developer 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB3311929.032%

문제

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 $n$ properties numbered from 1ドル$ to $n$ along the street. The area is somewhat hilly, and the elevation of the $i$-th property is $a_i$ centimetres.

It turns out that no one wants to buy a property that is on a slope. Formally, for elevations $a_1, a_2, \dots , a_n,ドル a slope is a contiguous subsequence $a_{i-1}, a_i , \dots , a_j , a_{j+1}$ with 2ドル ≤ i ≤ j ≤ n - 1$ such that either (i) $a_{i-1} < a_i = a_{i+1} = \dots = a_j < a_{j+1},ドル or (ii) $a_{i-1} > a_i = a_{i+1} = \dots = a_j > a_{j+1}$. Intuitively, a slope is a contiguous range of properties at positions $i - 1, i, i + 1, \dots , j, j + 1,ドル where the elevations of all properties at positions $i, i + 1, \dots , j$ are equal to some $h,ドル and $h$ is strictly between $a_{i-1}$ and $a_{j+1}$.

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 $b_1, b_2, \dots , b_n$ without slopes such that $|a_1 - b_1| + |a_2 - b_2| + \dots + |a_n - b_n|$ is as small as possible. The elevations $b_i$ must be integers (in particular, they don’t have to be positive), and there are no other constraints on $b_i$.

입력

The first line contains an integer $n$ (1ドル ≤ n ≤ 2 \cdot 10^5$) denoting the number of properties along the street.

The second line contains $n$ integers $a_1, a_2, \dots , a_n$ (0ドル ≤ a_i ≤ 10^9$), where the $i$-th integer $a_i$ is the initial elevation of the $i$-th property.

출력

You should output the minimal total change in elevation to ensure that there are no slopes.

제한

서브태스크

번호배점제한
14

$n ≤ 5$ and $a_i ≤ 10$

213

$n ≤ 2000$

38

$a_i ≤ 10$

419

$a_i < a_{i+1}$

529

$n ≤ 2 \cdot 10^4$

627

No additional constraints.

예제 입력 1

11
7 2 1 2 5 7 8 8 10 8 8

예제 출력 1

5

힌트

This is illustrated below. The dashed lines represent the changed elevations without slopes $b_i$ of their corresponding properties.

출처

Olympiad > Baltic Olympiad in Informatics > BOI 2025 D번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /