| Pinely Round 5 (Div. 1 + Div. 2) |
|---|
| Finished |
You are a customer in a store and want to buy $$$n$$$ items. Each item $$$i$$$ has a price $$$a_i$$$ such that $$$1 \leq a_i \leq X$$$, where $$$X$$$ is a loyalty factor.
Your loyalty level in the store is defined as $$$\lfloor {S \over X} \rfloor$$$, where $$$S$$$ is the total cost of items purchased so far. Initially, $$$S = 0$$$.
If you buy an item with price $$$p$$$ and your loyalty level increases as a result of this purchase, you earn $$$p$$$ bonus points.
Your task is to find the maximum number of bonus points you can earn by choosing an optimal order of purchase for the items.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ ($$$1 \leq n \leq 10^5$$$) and $$$X$$$ ($$$1 \leq X \leq 10^9$$$) — the number of items and the loyalty factor.
The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \leq a_i \leq X$$$) — the prices of the items.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output two lines.
The first line should contain a single integer — the maximum number of bonus points that can be earned.
The second line should contain $$$n$$$ integers — the prices of the items in an order of purchase that maximizes the number of bonus points.
If there are several orders that maximize the number of bonus points, you can output any of them.
710 21 2 1 2 1 2 1 2 1 25 102 2 2 2 511 235 5 22 1 21 2 10 3 1 1 21 111 17113 10044 32 116 10050042801 73112 95296 68791 42217 21871 29316 84405 24273 42894 63370 53473 57156 61369 80 27290
12 1 2 2 2 2 2 1 1 1 1 5 2 2 2 2 5 53 1 1 5 2 1 2 5 3 10 21 22 1 1 0 11 0 44 32 1 503499 53473 42894 80 57156 42801 61369 42217 63370 29316 68791 27290 73112 24273 84405 21871 95296
In the first test case:
Overall we got $$$12$$$ bonus points.
In the second test case:
In the third test case:
| Name |
|---|


