QOJ.ac

QOJ

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

#18153. Dora and C++

Statistics

Dora 刚刚学习了 C++ 编程语言!

然而,她完全误解了 C++ 的含义。她将其理解为对含有 $n$ 个元素的数组 $c$ 进行的两种加法操作。Dora 有两个整数 $a$ 和 $b$。在一次操作中,她可以选择执行以下操作之一:

  • 选择一个整数 $i$ 满足 $1 \le i \le n$,并将 $c_i$ 增加 $a$。
  • 选择一个整数 $i$ 满足 $1 \le i \le n$,并将 $c_i$ 增加 $b$。

注意,$a$ 和 $b$ 是常数,且它们可以相等。

我们定义数组 $d$ 的极差为 $\max(d_i) - \min(d_i)$。例如,数组 $[1, 2, 3, 4]$ 的极差为 $4 - 1 = 3$,数组 $[5, 2, 8, 2, 2, 1]$ 的极差为 $8 - 1 = 7$,而数组 $[3, 3, 3]$ 的极差为 $3 - 3 = 0$。

在进行任意次数(可能为 $0$ 次)的操作后,Dora 会计算新数组的极差。你需要帮助 Dora 最小化这个值。但由于 Dora 喜欢自己探索,你只需要告诉她最小化后的极差值即可。

输入格式

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

每个测试用例的第一行包含三个整数 $n$,$a$ 和 $b$ ($1 \le n \le 10^5$, $1 \le a, b \le 10^9$) — 分别表示数组 $c$ 的长度和常数值。

每个测试用例的第二行包含 $n$ 个整数 $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 10^9$) — 数组 $c$ 的初始元素。

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

输出格式

对于每个测试用例,输出一个整数 — 在进行任意次数的操作后,数组可能达到的最小极差。

样例

输入样例 1

10
4 5 5
1 3 4 4
4 2 3
1 3 4 6
4 7 7
1 1 2 6
3 15 9
1 9 5
3 18 12
1 4 5
7 27 36
33 13 23 12 35 24 41
10 6 9
15 5 6 9 8 2 12 15 3 8
2 1 1000000000
1 1000000000
6 336718728 709848696
552806726 474775724 15129785 371139304 178408298 13106071
6 335734893 671469786
138885253 7095920 456876775 9345665 214704906 375508929

输出样例 1

3
0
3
2
3
5
1
0
17
205359241

说明

在第一个测试用例中,我们可以将 $c_1 = 1$ 增加 $a = 5$。数组 $c$ 将变为 $[6, 3, 4, 4]$,其极差为 $3$。注意,达到该答案的方法可能不止一种。

在第二个测试用例中,我们可以将 $c_1 = 1$ 增加 $a = 2$(此时 $c_1$ 变为 $3$),然后将 $c_1 = 3$ 增加 $b = 3$。或者,我们也可以将 $c_2 = 3$ 增加 $b = 3$,并将 $c_3 = 4$ 增加 $a = 2$。数组 $c$ 将变为 $[6, 6, 6, 6]$,其极差为 $0$。

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.