-
[1651] Red packet
- 时间限制: 1000 ms 内存限制: 65535 K
- 问题描述
-
New Year is coming! Our big boss Wine93 will distribute some “Red Package”, just like Alipay and Wechat.
Wine93 has m yuan, he decides to distribute them to n people and everyone can get some money(0 yuan is not allowed and everyone’s money is an integer), Now k people has gotten money, it’s your turn to get “Red Package”, you want to know, at least how much money to give you, then you can must become the “lucky man”. and the m yuan must be used out.
Noting that if someone’s money is strictly much than others’, than he is “lucky man”.
- 输入
- Input starts with an integer T (T <= 50) denoting the number of test case. For each test case, three integers n, m, k (1 <= k < n <= 100000, 0< m <= 100000000) will be given. Next line contains k integers, denoting the money that k people get. You can assume that the k integers’ summation is no more than m.
- 输出
- Ouput the least money that you need to become the “lucky man”, if it is impossible, output “Impossible” (no quote).
- 样例输入
-
33 5 22 14 10 22 34 15 23 5
- 样例输出
-
Impossible46
以前红包专场的题目,当时实在是水平低下,天真的以为可以拿点钱,结果被爆0血虐(Orz各位学长学姐老司机们)。
于是现在又回来噜一下这题,发现挺简单的……就是二分的时候剩下的除我之外其他人的钱忘记减1,WA两次才发现……
主要思路:记录剩余的钱为res,出现过的最高红包额度记为maxm,特判掉impossib的情况之后,二分的左端点肯定是maxm+1,右端点显然要奢侈一点取最好情况即剩下的人均只分到1元,那么我就有res-(n-k-1)元,然后唯一的竞争对手就是另外一个人,他有res-(n-k-2)-mid元,条件是不能让他大于等于我,然后二分就可以了……,以前还傻乎乎地看不懂二分的条件还跑论坛里问别人这是什么意思…………Naive。
代码:
#include#include #include #include #include #include #include #include #include #include #include #include #include #include