-
[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).
- 样例输入
-
3 3 5 2 2 1 4 10 2 2 3 4 15 2 3 5
- 样例输出
- 提示
-
无
-
WA了5次,4次就是因为没看清题目要求,you can must become the “lucky man”。。。。。。。。。。
-
并且这道题并不能说是二分吧。。
-
#include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; int a[110000]; int main() { int t,k,m,n,i,j,l,r; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); int sum=0; for(i=0;i<k;i++) { scanf("%d",&a[i]); sum+=a[i]; } sort(a,a+k); m=m-sum; n=n-k; if(n==1) { l=r=m; } else { if(m==n) { r=0; } else { l=(m-(n-2))/2+1; r=m-(n-1); } } l=max(l,a[k-1]+1); if(l<=r) { printf("%d\n",l); } else printf("Impossible\n"); } return 0; }
NbUT 1651Red packet
最新推荐文章于 2019-09-06 22:36:00 发布