CF1928D.Lonely Mountain Dungeons

普及/提高-

通过率:0%

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 bb 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 kk squads is reduced by (k1)x(k - 1) \cdot x units. Note that the army always consists of at least one squad.

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

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt ( 1t21041 \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 nn , bb , and xx ( 1n21051 \le n \le 2 \cdot 10^5 , 1b106,0x1091 \le b \le 10^6, 0 \le x \le 10^9 ) — the number of races and the constants bb and xx described above.

The second line of each test case contains nn integers c1,c2,,cnc_1, c_2, \ldots, c_n ( 1ci21051 \le c_i \le 2 \cdot 10^5 ) — the number of creatures of each of the nn races.

It is guaranteed that the sum of the values c1+c2++cnc_1 + c_2 + \ldots + c_n over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

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 33 squads. Since x=0x = 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=1b = 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 3b=33 \cdot b = 3 , as they form three pairs in different squads.

Thus, the total strength of the army is 44 .

In the second test case, the inhabitants of Middle-earth can form 33 squads. Since x=10x = 10 , the army's strength will decrease by 2020 . 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=5b = 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 third species can be sent to the third squad. Then the total strength of the army will increase by 8b=408 \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 3b=153 \cdot b = 15 , as they form three pairs in different squads.

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

首页