포럼
문제 ICPC00389

M. Musical Mending

설명

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 illustrates a solution for Sample Input 3, resulting in a total tuning effort of 23.

제약
입력 형식

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
출력
0
예제 2
입력
5
0 1 4 3 6
출력
4
예제 3
입력
6
0 -2 10 6 7 -1
출력
23
예제 4
입력
4
0 -4 -2 1
출력
7
예제 5
입력
9
0 23452 145043 -3423 -20 9845 435 -3 4453
출력
186237
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC GCPC 2024

평가 및 의견

M. Musical Mending

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

M. Musical Mending

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8