QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#14248. Herdier Immunity

Estadísticas

你拥有一群可爱的哈约克(Herdier),数量为 $N$,编号为 $1$ 到 $N$。每天你都会将它们按编号顺序排成一排,并充满爱意地清点它们,以表达你对它们的喜爱。不幸的是,有一天悲剧发生了,你的哈约克中有 $M$ 只突然患上了一种神秘的疾病。幸运的是,病情并不严重,但你仍然希望利用科学的力量来最大程度地减少这种疾病的传播。

你可爱的哈约克

每天当你的哈约克排好队时,每只已经感染的哈约克都会感染任何未感染的相邻哈约克(如果 $|i - j| = 1$,则编号为 $i$ 和 $j$ 的两只哈约克被认为是相邻的)。然而,你每天早上都会获得一支疫苗。在每天排队之前,你都可以为一只尚未被感染的哈约克接种疫苗。在哈约克接种疫苗后,即使在未来的日子里也不会被感染。你每天继续为哈约克接种疫苗,直到所有的哈约克要么生病,要么接种了疫苗。你最多可以为多少只哈约克接种疫苗?

输入格式

输入的第一行包含两个空格分隔的整数 $N$ 和 $M$。这表示哈约克的总数($1 \le N \le 10^9$)和最初生病的哈约克数量($1 \le M \le 100\,000$)。

第二行包含 $M$ 个互不相同的空格分隔的整数 $a_1, \dots, a_M$($1 \le a_1 < \dots < a_M \le N$),其中每个 $a_i$ 表示编号为 $a_i$ 的哈约克最初被感染。

输出格式

输出单行,包含你最多可以接种疫苗的哈约克数量。

样例

输入样例 1

3 1
2

输出样例 1

1

输入样例 2

12 2
4 9

输出样例 2

5

输入样例 3

23 3
4 12 20

输出样例 3

8

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.