#H2026B. Be the One
Be the One
Description
Larutan gives Natural a multiset of positive integers. A multiset may contain multiple occurrences of the same value.
Natural may perform either of the following operations any number of times:
- If the multiset contains at least two occurrences of a value , delete one occurrence of . This operation costs units of time.
- Choose one occurrence of a value and replace it with . This operation costs units of time.
Values produced by the second operation are also part of the multiset and may be used in subsequent operations.
Determine the minimum total time required to reduce the multiset to exactly one remaining element.
Input Format
The first line contains one integer , the number of test cases.
Each test case consists of two lines:
- The first line contains three integers , , and , where is the number of elements, is an upper bound on their values, and is the cost of one replacement operation.
- The second line contains integers , representing the initial multiset.
Output Format
For each test case, output the minimum total time on a separate line.
Sample
Input #1
1
5 10 3
1 1 3 5 5
Output #1
17
Sample Explanation
Consider the initial multiset .
Perform the following operations:
- Delete one occurrence of . The multiset becomes , at a cost of .
- Replace with . The multiset becomes , at a cost of .
- Replace with . The multiset becomes , at a cost of .
- Replace with . The multiset becomes , at a cost of .
- Delete one occurrence of . The multiset becomes , at a cost of .
- Delete one occurrence of . The multiset becomes , at a cost of .
- Delete one occurrence of . The multiset becomes , at a cost of .
The total cost is , which is the minimum possible cost.
Constraints
For all test cases:
- ;
- and the sum of over all test cases does not exceed ;
- ;
- ;
- .
相关
在下列比赛中: