#P9884. [EC Final 2021] Prof. Pang and Ants

    ID: 9288 Type: RemoteJudge 8000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2021Special JudgeO2优化ICPC

[EC Final 2021] Prof. Pang and Ants

题目描述

Near Prof. Pang's big house, there is an ant group which has mm ants and lives underground in a cave with nn holes. They get out of the holes for food. So where is the food? It should be in Prof. Pang's big refrigerator. The ants want to steal the food from the big refrigerator.

Specifically, for an ant, it needs 11 second to leave from the cave through any hole and 11 second to enter the cave through any hole. Different holes have different locations. The distance between the ii-th hole and the refrigerator is aia_i. Thus, after leaving the cave through the ii-th hole, an ant needs aia_i seconds to go to the refrigerator. After stealing some food from the refrigerator, an ant needs aia_i seconds to go back to the ii-th hole. Stealing food costs no time for the ants since they are skillful enough.

Each ant will leave the cave to steal something from the refrigerator and return to (enter) the cave after stealing. Each ant must leave the cave exactly once and then return to the cave. One ant can arbitrarily choose one hole to leave and also arbitrarily choose one hole to enter, where the two holes need not be the same. For any hole, during any second, there can be at most one ant leaving or entering the cave through it. There cannot be one ant leaving the cave and another ant entering the cave using the same hole during the same second. Because of this capacity constraint, some ants may need to wait before they leave the hole and/or before they return to the hole after stealing.

So you, Prof. Pang's good friend, need to calculate the minimum time cost for ants to achieve the goal and play a trick on Prof. Pang so that the ants can steal the food without being caught by Prof. Pang. The time cost is defined as the total length of time during which at least one ant is not in the cave. When an ant is entering or leaving the cave through some hole, it is not in the cave.

输入格式

The first line contains a single integer T (1T105)T~(1 \le T \le 10^5) denoting the number of test cases.

For each test case, the first line contains two integers n,mn,m (1n105,1m10141\le n \le 10^5, 1\le m \le 10^{14}) denoting the number of the holes and the number of the ants respectively. The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (1ai1091\le a_i \le 10^9) denoting the time needed to get to the refrigerator from the ii-th hole.

It is guaranteed that the sum of nn over all test cases will not exceed 5×1055\times 10^5.

输出格式

For each test case, print one line containing one integer denoting the minimum time cost in seconds.

3
2 4
1 2
3 10
1 2 3
5 1
1 2 3 4 5

6
9
4

提示

In the third test case, it takes the ant 22 seconds to leave and enter the cave through the first hole. And it takes the ant 22 seconds to move to the refrigerator and back to the hole.