CF2042A Greedy Monocarp
题目描述
有 $n$ 个宝箱,第 $i$ 个有 $a_i$ 枚金币。对于每个宝箱,你可以加入任何非负整数枚金币,最终使得所有宝箱中金币的总数不小于 $k$。
在你加入金币之后,贪婪的 Monocarp 会来取金币。他会一个一个的取走宝箱,每次取走金币最多的宝箱,直到他取走金币的总数至少为 $k$。
你想要 Monocarp 取走尽量少的金币,所以你需要给宝箱增加一定的金币,使得 Monocarp 取走恰好 $k$ 枚金币。算出你最少需要加入多少枚金币。
输入格式
第一行,一个整数 $t$ ($1\le t\le 1000$),表示数据组数。
对于每组数据,输入两行:
- 第一行,两个整数 $n,k$ ($1\le n\le 50$;$1\le k\le 10^7$);
- 第二行,$n$ 个整数,$a_1,a_2,\cdots ,a_n$(保证 $1\le a_i\le k$)。
输出格式
对于每组数据,输出一个整数,表示使 Monocarp 拿走恰好 $k$ 枚金币,至少需要额外加入多少枚金币。可以证明在题目条件下一定有解。
翻译:[HYdroKomide](https://www.luogu.com.cn/user/299883)
说明/提示
In the first test case of the example, you don't have to add any coins. When Monocarp arrives, he will take the chest with $ 4 $ coins, so he will have exactly $ 4 $ coins.
In the second test case of the example, you can add $ 1 $ coin to the $ 4 $ -th chest, so, when Monocarp arrives, he will take a chest with $ 4 $ coins, then another chest with $ 4 $ coins, and a chest with $ 2 $ coins.
In the third test case of the example, you can add $ 3 $ coins to the $ 1 $ -st chest and $ 5 $ coins to the $ 2 $ -nd chest.
In the fourth test case of the example, you can add $ 1 $ coin to the $ 1 $ -st chest and $ 1 $ coin to the $ 3 $ -rd chest.