# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

In the land of Minion, there are **N** Minions. They have their own power to survive themselves from enemy.

The power of every Minion may not always be equal. But, their power must to be equal as you don’t want a war among themselves. **So, you need to make the every Minion’s power equal.**

You can increase or decrease any Minion’s power by 1 as many time as you want.

But nothing is free here! Increasing a Minion’s power by 1 will cost **P** and decreasing a Minion’s power by 1 will cost **Q**.

You need to find the minimum cost to make every Minion’s power equal.

The input will be followed by an integer **T**, denoting the number of test case.

The first line of each test case will contain three integers **N**, **P** and **Q**.
The second line will contain **N** integers denoting the power of Minions.

1 ≤ T ≤ 10

1 ≤ N, P, Q ≤ 10^{6}

1 ≤ Minion’s Power ≤ 10^{6}

Sum of N over all the test cases ≤ 8 * 10^{6}

For each test case, the only line of the output will contain the minimum cost to make every Minion’s power equal.

Input | Output |
---|---|

1 3 1 1 1 2 3 | 2 |

64% Solution Ratio

ehsan_sShuvoEarliest,

Riaz_BSMRSTUFastest, 0.9s

moinul.shaonLightest, 4.1 MB

IOI_StfuFfsShortest, 665B

Login to submit