#P13728. [GCPC 2024] Musical Mending
[GCPC 2024] 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 M.1 illustrates a solution for Sample Input 3, resulting in a total tuning effort of 23.
:::align{center}
Figure M.1: Visualization of Sample Input 3. :::
输入格式
The input consists of:
- One line with an integer (), the number of keys on the piano.
- One line with integers (), where describes the difference in pitch between the th key and the first key. The first integer is always .
输出格式
Output the minimal total tuning effort.
7
0 1 2 3 4 5 6
0
5
0 1 4 3 6
4
6
0 -2 10 6 7 -1
23
4
0 -4 -2 1
7
9
0 23452 145043 -3423 -20 9845 435 -3 4453
186237