311060: CF1928D. Lonely Mountain Dungeons

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Lonely Mountain Dungeonstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Once, the people, elves, dwarves, and other inhabitants of Middle-earth gathered to reclaim the treasures stolen from them by Smaug. In the name of this great goal, they rallied around the powerful elf Timothy and began to plan the overthrow of the ruler of the Lonely Mountain.

The army of Middle-earth inhabitants will consist of several squads. It is known that each pair of creatures of the same race, which are in different squads, adds $b$ units to the total strength of the army. But since it will be difficult for Timothy to lead an army consisting of a large number of squads, the total strength of an army consisting of $k$ squads is reduced by $(k - 1) \cdot x$ units. Note that the army always consists of at least one squad.

It is known that there are $n$ races in Middle-earth, and the number of creatures of the $i$-th race is equal to $c_i$. Help the inhabitants of Middle-earth determine the maximum strength of the army they can assemble.

Input

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains three integers $n$, $b$, and $x$ ($1 \le n \le 2 \cdot 10^5$, $1 \le b \le 10^6, 0 \le x \le 10^9$) — the number of races and the constants $b$ and $x$ described above.

The second line of each test case contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 2 \cdot 10^5$) — the number of creatures of each of the $n$ races.

It is guaranteed that the sum of the values $c_1 + c_2 + \ldots + c_n$ over all test cases does not exceed $2 \cdot 10^5$.

Output

For each test case, output a single integer — the maximum strength of the army that the inhabitants of Middle-earth can assemble.

ExampleInput
5
3 1 0
1 2 3
3 5 10
2 5 3
4 3 3
3 2 1 2
4 1 0
4 1 4 2
4 1 10
4 1 4 2
Output
4
40
9
13
0
Note

In the first test case, the inhabitants of Middle-earth can form $3$ squads. Since $x = 0$, the army's strength will not decrease due to the number of squads. The inhabitants can be distributed among the squads as follows:

  • The single representative of the first species can be sent to the first squad.
  • The first representative of the second species can be sent to the first squad, the second representative of the second species can be sent to the second squad. Then the total strength of the army will increase by $b = 1$.
  • The first representative of the third species can be sent to the first squad, the second representative of the third species can be sent to the second squad, the third representative of the third species can be sent to the third squad. Then the total strength of the army will increase by $3 \cdot b = 3$, as they form three pairs in different squads.

Thus, the total strength of the army is $4$.

In the second test case, the inhabitants of Middle-earth can form $3$ squads. Since $x = 10$, the army's strength will decrease by $20$. The inhabitants can be distributed among the squads as follows:

  • The first representative of the first species can be sent to the first squad, the second representative of the first species can be sent to the second squad. Then the total strength of the army will increase by $b = 5$.
  • The first and second representatives of the second species can be sent to the first squad, the third and fourth representatives of the second species can be sent to the second squad, the fifth representative of the second species can be sent to the third squad. Then the total strength of the army will increase by $8 \cdot b = 40$.
  • The first representative of the third species can be sent to the first squad, the second representative of the third species can be sent to the second squad, the third representative of the third species can be sent to the third squad. Then the total strength of the army will increase by $3 \cdot b = 15$, as they form three pairs in different squads.

Thus, the total strength of the army is $5 + 40 + 15 - 20 = 40$.

Output

题目大意:
这个题目是关于中土世界的居民组织军队来夺回被斯毛格偷走的宝藏。军队由几个小队组成,每对同一种族且在不同小队的生物可以为军队的总力量增加b单位。但是,由于小队数量太多,领导将会变得困难,所以由k个小队组成的军队的总力量会减少(k - 1) * x单位。注意,军队总是至少由一个小队组成。

中土世界有n个种族,第i个种族的生物数量为c_i。帮助中土世界的居民确定他们可以组成的最大军队力量。

输入输出数据格式:
输入:
- 第一行包含一个整数t(1 ≤ t ≤ 2 * 10^4),表示测试用例的数量。
- 每个测试用例的第一行包含三个整数n、b和x(1 ≤ n ≤ 2 * 10^5,1 ≤ b ≤ 10^6,0 ≤ x ≤ 10^9),分别表示种族的数量和上述的常数b和x。
- 每个测试用例的第二行包含n个整数c_1, c_2, ..., c_n(1 ≤ c_i ≤ 2 * 10^5),表示每个种族的生物数量。

输出:
- 对于每个测试用例,输出一个整数,表示中土世界居民可以组成的最大军队力量。题目大意: 这个题目是关于中土世界的居民组织军队来夺回被斯毛格偷走的宝藏。军队由几个小队组成,每对同一种族且在不同小队的生物可以为军队的总力量增加b单位。但是,由于小队数量太多,领导将会变得困难,所以由k个小队组成的军队的总力量会减少(k - 1) * x单位。注意,军队总是至少由一个小队组成。 中土世界有n个种族,第i个种族的生物数量为c_i。帮助中土世界的居民确定他们可以组成的最大军队力量。 输入输出数据格式: 输入: - 第一行包含一个整数t(1 ≤ t ≤ 2 * 10^4),表示测试用例的数量。 - 每个测试用例的第一行包含三个整数n、b和x(1 ≤ n ≤ 2 * 10^5,1 ≤ b ≤ 10^6,0 ≤ x ≤ 10^9),分别表示种族的数量和上述的常数b和x。 - 每个测试用例的第二行包含n个整数c_1, c_2, ..., c_n(1 ≤ c_i ≤ 2 * 10^5),表示每个种族的生物数量。 输出: - 对于每个测试用例,输出一个整数,表示中土世界居民可以组成的最大军队力量。

加入题单

上一题 下一题 算法标签: