QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#9312. 随机地下城

Statistics

Mike 正在玩一款名为“随机地下城”(Random Dungeon)的电子游戏。

在这个游戏中,你每周都要挑战地下城并根据你的得分获得奖励。

Mike 发现该地下城共有 $N$ 种变体,编号从 $1$ 到 $N$。Mike 将挑战该地下城 $N$ 次,对于每一次挑战,游戏会以相等的概率从尚未出现的变体中选择一种。

挑战地下城变体 $i$ 时,Mike 将获得 $A_i$ 分。他可以在完成一次挑战后随时选择停止,此时他的最终得分将是最后一次挑战的得分。在每周结束时,如果他的最终得分是 $x$,他将获得 $x$ 枚金币。然而,挑战地下城需要花费金币。每次挑战的费用为 $C$ 枚金币。

如果 Mike 采取行动以最大化预期利润(每周结束时获得的金币减去挑战花费的金币),请计算该预期利润。

输入格式

第一行包含两个整数 $N$ 和 $C$ ($1 \le N \le 2 \cdot 10^5$, $1 \le C \le 10^9$)。

第二行包含 $N$ 个整数 $A_1, A_2, \dots, A_N$ ($1 \le A_i \le 10^9$),表示 Mike 挑战地下城变体 $i$ 获得的分数。

输出格式

输出预期利润。如果你的答案与标准答案之间的绝对误差或相对误差不超过 $10^{-9}$,则视为正确。即,如果正确答案为 $x$,你的答案为 $y$,当 $\frac{|x-y|}{\max\{1,|x|\}} \le 10^{-9}$ 时,你的答案将被视为正确。

样例

样例输入 1

3 1
1 2 3

样例输出 1

1.1666666667

样例输入 2

3 3
1 2 3

样例输出 2

-1.0000000000

样例输入 3

9 193138187
782710197 539624191 631858791
976609486 752268030 30225807
279200011 467188665 630132600

样例输出 3

442999078.5373015873

说明

在第一个样例中,Mike 的最优策略是:如果第一次挑战的地下城是变体 2 或 3,则停止;否则,进行第二次挑战并停止。预期利润为 $\frac{1}{3} \cdot (2 - 1) + \frac{1}{3} \cdot (3 - 1) + \frac{1}{3} \cdot (\frac{2+3}{2} - 2) = \frac{7}{6}$。

在第二个样例中,Mike 的最优策略是:只进行一次挑战并停止。

第三个样例包含额外的换行符以适应表格格式。

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.