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

32489번 - Musical Mending 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB122796565.657%

문제

Shortly before the concert starts, you notice that your piano is completely out of tune! Having the ability of relative pitch, you are able to discern the difference between the pitch of any piano key to the first piano key. While this does not help you find the absolute pitch, you decide to at least tune the keys relative to each other. To do this, you need to make sure that the pitch of each key is exactly one higher than the key before it and one lower than the key after it. As the concert will start shortly, you need to minimize the total tuning effort, which is the sum of the absolute changes in pitch you apply to each key. For example, Figure M.1 illustrates a solution for Sample Input 3, resulting in a total tuning effort of 23.

Figure M.1: Visualization of Sample Input 3.

입력

The input consists of:

  • One line with an integer $n$ (2ドル \leq n \leq 10^5$), the number of keys on the piano.
  • One line with $n$ integers $t_1,\dots,t_n$ ($-2 \cdot 10^5 \leq t_i \leq 2 \cdot 10^5$), where $t_i$ describes the difference in pitch between the $i$th key and the first key. The first integer $t_1$ is always 0ドル$.

출력

Output the minimal total tuning effort.

제한

예제 입력 1

7
0 1 2 3 4 5 6

예제 출력 1

0

예제 입력 2

5
0 1 4 3 6

예제 출력 2

4

예제 입력 3

6
0 -2 10 6 7 -1

예제 출력 3

23

예제 입력 4

4
0 -4 -2 1

예제 출력 4

7

예제 입력 5

9
0 23452 145043 -3423 -20 9845 435 -3 4453

예제 출력 5

186237

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > German Collegiate Programming Contest > GCPC 2024 M번

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

출처

대학교 대회

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

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