QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 1024 MB Puntuación total: 100

#12149. 音乐修补

Estadísticas

在音乐会开始前不久,你发现你的钢琴完全走音了!凭借相对音感,你能够辨别出钢琴上任意琴键与第一个琴键之间的音高差。虽然这无法帮你找到绝对音高,但你决定至少将琴键彼此相对调准。为此,你需要确保每个琴键的音高恰好比前一个琴键高 1,且比后一个琴键低 1。由于音乐会即将开始,你需要最小化总调音工作量,即你对每个琴键所施加的音高绝对变化量之和。例如,图 M.1 展示了样例输入 3 的一种解决方案,其总调音工作量为 23。

图 M.1:样例输入 3 的可视化。

输入格式

输入包含: 一行包含一个整数 $n$ ($2 \le n \le 10^5$),表示钢琴上的琴键数量。 一行包含 $n$ 个整数 $t_1, \dots, t_n$ ($-2 \cdot 10^5 \le t_i \le 2 \cdot 10^5$),其中 $t_i$ 描述了第 $i$ 个琴键与第一个琴键之间的音高差。第一个整数 $t_1$ 始终为 0。

输出格式

输出最小的总调音工作量。

样例

样例输入 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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.