QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#7504. 炉石传说

统计

Alice 喜欢玩《炉石传说》!她非常喜欢术士职业,因为术士可以施放名为“亵渎”的法术。

当施放“亵渎”时,它会对所有随从造成 1 点伤害。如果此时有任何随从死亡,“亵渎”会自动再次施放。需要注意的是,如果两个或更多的随从同时死亡,它仍然只会触发一次“亵渎”的再次施放。这反过来可能会杀死其他随从,导致“亵渎”再次施放,以此类推。

每个随从的生命值都是一个非负整数。当随从的生命值变为 0 时,它就会死亡。如果一个随从死亡,它就会消失。它不会死亡两次。

现在有 $n$ 个随从。在施放“亵渎”之前,Alice 可以进行零次或多次操作。在每一步操作中,Alice 可以将某个随从的生命值改变 1。也就是说,如果一个随从的生命值是 $x$,Alice 可以将其变为 $x - 1$ 或 $x + 1$。

Alice 想知道,为了能在操作后施放一次“亵渎”并消灭所有随从,她最少需要进行多少步操作。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10^6$)。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$),表示 $n$ 个随从的生命值。

输出格式

输出一个整数:在 Alice 能够施放一次“亵渎”并消灭所有随从之前,所需的最少操作步数。

样例

输入 1

6
4 6 8 9 2 4

输出 1

12

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.