| Codeforces Round 1138 (Div. 3) |
|---|
| Finished |
After making the sweet toast, Sunny and Aubrey turned their attention to the grapefruits that Sunny had brought for their picnic.
They have $$$n$$$ grapefruits in total. The $$$i$$$-th grapefruit has a taste value of $$$a_i$$$.
They can enjoy the grapefruits in two ways:
Each grapefruit can be used only once: either eaten fresh or used to make a glass of juice. They can make any number of glasses of juice.
What is the maximum total number of joy points they can gain?
Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 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$$$, $$$k$$$, and $$$p$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le n$$$, $$$1 \le p \le 10^9$$$) — the number of grapefruits, the number of fruits per glass of juice, and the joy points for a glass of juice.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the taste ratings of the grapefruits.
The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print a single integer — the maximum possible total joy.
The answer may not fit into a 32-bit signed integer.
74 2 103 1 4 23 3 10010 20 303 1 52 3 14 2 53 1 1 13 2 109 1 22 2 48 74 2 51 1 9 9
201001510191523
In the second test case, one glass gives $$$100$$$ points. Eating all three fruits fresh gives $$$10+20+30=60$$$ points.
In the fifth test case, the friends can squeeze the fruits rated $$$1$$$ and $$$2$$$ and eat the fruit rated $$$9$$$ fresh. This gives $$$10+9=19$$$ points. Eating all three fresh would give $$$12$$$ points.
In the seventh test case, using the two fruits rated $$$1$$$ for one glass gives $$$5+9+9=23$$$ points. Making no juice gives $$$20$$$ points, and making two glasses gives $$$10$$$.
| Name |
|---|


