CF1928D.Lonely Mountain Dungeons
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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)⋅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 ci. Help the inhabitants of Middle-earth determine the maximum strength of the army they can assemble.
曾经,中土大陆的人民、精灵、矮人及其他居民聚集起来,旨在夺回被史矛革窃取的宝藏。为了实现这一伟大目标,他们团结在强大的精灵蒂莫西周围,开始筹划推翻孤山之王的统治。
中土大陆居民组成的军队将由若干支小队构成。已知:对于任意同一种族的两个生物,若它们分属不同的小队,则会使军队总战力增加 b 单位。但由于蒂莫西难以统率小队数量过多的军队,因此由 k 支小队组成的军队,其总战力将减少 (k−1)⋅x 单位。注意:军队至少包含一支小队。
已知中土大陆共有 n 个种族,其中第 i 个种族的生物数量为 ci。请帮助中土大陆的居民确定他们所能组建的军队的最大战力。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤2⋅104) — 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≤n≤2⋅105, 1≤b≤106,0≤x≤109) — the number of races and the constants b and x described above.
The second line of each test case contains n integers c1,c2,…,cn (1≤ci≤2⋅105) — the number of creatures of each of the n races.
It is guaranteed that the sum of the values c1+c2+…+cn over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤2⋅104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含三个整数 n、b 和 x(1≤n≤2⋅105,1≤b≤106,0≤x≤109),分别表示种族数量以及上述描述的常数 b 和 x。
每个测试用例的第二行包含 n 个整数 c1,c2,…,cn(1≤ci≤2⋅105),表示 n 个种族各自的生物数量。
保证所有测试用例中 c1+c2+…+cn 的总和不超过 2⋅105。
输出格式
For each test case, output a single integer — the maximum strength of the army that the inhabitants of Middle-earth can assemble.
对于每个测试用例,输出一个整数——中土世界居民所能组建的军队的最大战力。
输入输出样例
输入#1
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
输出#1
4 40 9 13 0
说明/提示
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⋅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⋅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⋅b=15, as they form three pairs in different squads.
Thus, the total strength of the army is 5+40+15−20=40.
在第一个测试用例中,中土大陆的居民可以组成 3 支小队。由于 x=0,军队总战力不会因小队数量而下降。居民可在各小队间按如下方式分配:
- 第一物种的唯一代表可派往第一支小队。
- 第二物种的第一位代表可派往第一支小队,第二位代表可派往第二支小队。此时军队总战力将增加 b=1。
- 第三物种的第一位代表可派往第一支小队,第二位代表可派往第二支小队,第三位代表可派往第三支小队。由于他们在不同小队中构成了三对,军队总战力将增加 3⋅b=3。
因此,军队总战力为 4。
在第二个测试用例中,中土大陆的居民可以组成 3 支小队。由于 x=10,军队总战力将减少 20。居民可在各小队间按如下方式分配:
- 第一物种的第一位代表可派往第一支小队,第二位代表可派往第二支小队。此时军队总战力将增加 b=5。
- 第二物种的第一、二位代表可派往第一支小队,第三、四位代表可派往第二支小队,第五位代表可派往第三支小队。此时军队总战力将增加 8⋅b=40。
- 第三物种的第一位代表可派往第一支小队,第二位代表可派往第二支小队,第三位代表可派往第三支小队。由于他们在不同小队中构成了三对,军队总战力将增加 3⋅b=15。
因此,军队总战力为 5+40+15−20=40。
输入解题思路,AI测评打分。不知道怎么写?