Red packet NBUT
来源:互联网 发布:seo关键字是什么 编辑:程序博客网 时间:2024/05/17 18:18
[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
5 15 1
3 你应该得到6,否则不可能;
难倒是不难,注意二分的起末;
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;typedef long long LL;int main(){int j,m,t,n,k,p,maxn;scanf("%d",&t);while(t--){maxn=0,j=0;scanf("%d %d %d",&n,&m,&k);for(int i=0;i<k;i++){scanf("%d",&p);maxn=max(maxn,p);m-=p;}int ans=m-(n-k-1);if(ans<=maxn){printf("Impossible\n");continue;}if(n-k-1==0){printf("%d\n",m);continue;}int l=maxn+1,r=m,mid;while(r>=l){mid=(l+r)/2;int res=m-(n-k-2)-mid;if(mid>res) r=mid-1;else l=mid+1;}printf("%d\n",l);}return 0;}
阅读全文
1 0
- NbUT 1651Red packet
- 【NBUT】[1651]Red packet
- NBUT 1651 Red packet
- Red packet NBUT
- 【NBUT】1651 - Red packet(二分)
- Red packet
- Red packet
- [1651] Red packet【二分】
- 水题 nbut1651 Red packet
- Red packet 二分
- Noj 1651 Red packet
- I - Red packet
- Red packet【二分】
- Red packet~二分
- Red packet (二分)
- 【NBUTOJ】Red packet
- Red packet 二分算法
- Red packet 【模拟】
- 调用DLL函数,出现错误 Run-Time Check Failure #0
- Git下载及安装环境配置
- 多重背包问题
- AI黑科技来袭 2017北京硅谷高创会携PanguVR一窥智慧未来
- 谈谈java的运行机制
- Red packet NBUT
- 关于6.828实验中的bootloader链接地址与加载地址的思考
- 基于Swift的iOS应用程序开发:使用表格显示并控制数据(二):删除表格中的数据
- GPU编程
- 【转载】图解WebGL&Three.js工作原理
- python科学计算_numpy_函数库
- poj3061
- UI控件之ScrollView
- IntelliJ IDEA 设置代码提示或自动补全的快捷键