QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#3967. 细致平滑

统计

手工课老师看着你在木工坊制作的精美木板,神情严肃地盯着你:“这还不够光滑!多用点砂纸!”

你的木板长 $n$ 厘米,老师在 $k$ 个不同的位置测量了木板的厚度以证明他的观点。他要求任意两个相邻测量位置之间的厚度差不得超过 1 微米。如果每次在特定位置使用砂纸都会磨掉 1 微米的木头,那么你需要使用多少次砂纸?

输入格式

第一行包含一个整数 $1 \le n \le 10^6$,表示木板的长度。第二行包含 $n$ 个空格分隔的整数 $k_1, k_2, \dots, k_n$,表示木板在各处的厚度(对于每个 $i$,满足 $1 \le k_i \le 10^6$)。

输出格式

输出一个整数,表示你需要使用砂纸的最少次数(假设砂纸每次只能打磨一个位置)。

样例

样例输入 1

5
1 6 7 2 5

样例输出 1

10

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.