QOJ.ac

QOJ

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

#15709. Billion Players Game

Statistics

你正在关注“十亿玩家游戏”(Billion Players Game)的世界锦标赛。共有 $10^9$ 名玩家参赛,你想预测你最喜欢的博主 Godflex 的最终排名 $p$。在分析了最近的比赛后,你确定 $l \le p \le r$,但除此之外你一无所知。

游戏内的庄家提供了 $n$ 个报价。在第 $i$ 个报价中,庄家给出了 Godflex 最终排名的一个预测值 $a_i$。对于每个报价,你必须恰好选择以下操作之一:

  • 忽略该报价。
  • 接受该报价,并声称 $p \le a_i$。如果你猜对了,你将获得 $|p - a_i|$ 枚硬币;否则,你将失去 $|p - a_i|$ 枚硬币。
  • 接受该报价,并声称 $p \ge a_i$。如果你猜对了,你将获得 $|p - a_i|$ 枚硬币;否则,你将失去 $|p - a_i|$ 枚硬币。

在你决定好如何处理所有报价后,真正的“十亿玩家游戏”将会进行。Godflex 将获得 $[l, r]$ 范围内的一个整数排名 $p$,然后结算所有报价。

你的总得分是你保证能够获得的硬币数量,即在 $[l, r]$ 范围内所有可能的 $p$ 值中,你所能获得的硬币数量的最小值。求出你能够保证的最大可能得分。

输入格式

每个测试点包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 10^4$)。接下来是每个测试用例的描述。

每个测试用例的第一行包含三个整数 $n, l, r$ ($1 \le n \le 2 \cdot 10^5$, $1 \le l \le r \le 10^9$) —— 报价的数量以及 Godflex 最终排名的可能范围。

每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) —— 庄家在每个报价中对 Godflex 排名的预测值。

保证所有测试用例中 $n$ 的总和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数:你能够保证的最大可能得分。

样例

输入样例 1

4
1 1 5
3
2 100 100
50 200
5 1 10
5 7 3 9 1
5 6 10
9 3 1 7 5

输出样例 1

0
150
12
13

说明

样例 1 说明:在第一个测试用例中,只有一个报价。

  • 如果你忽略该报价,你的得分是 $0$;
  • 如果你接受该报价并声称 $p \le 3$,你的得分是 $-2$(在 $p = 5$ 时达到,此时你失去 $|5 - 3| = 2$ 枚硬币);
  • 如果你接受该报价并声称 $p \ge 3$,你的得分是 $-2$(在 $p = 1$ 时达到,此时你失去 $|1 - 3| = 2$ 枚硬币)。

因此,能够保证的最大可能得分是 $0$。

在第二个测试用例中,最优策略是接受声称 $p \ge 50$ 和 $p \le 200$ 的报价。由于 $p$ 必须为 $100$,你将获得 $|100 - 50| + |100 - 200| = 150$ 枚硬币。

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.