Noj Red packet -1651 (二分)
来源:互联网 发布:java如何制作图片上传 编辑:程序博客网 时间:2024/05/17 21:40
[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
- 样例输出
Impossible
4
6
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #define ll long long #define N 10010 using namespace std; int main() { int t,n,m,k,i,j,a; scanf("%d",&t); while(t--) { int sum=0; int mm=0; scanf("%d%d%d",&n,&m,&k); for(i=0;i<k;i++) { scanf("%d",&a); sum+=a; mm=max(mm,a); } int s=m-sum; int nk=n-k; int nnk=nk-1; int ss=s-nnk; int ma=mm+1; if(s-nnk<=mm) printf("Impossible\n"); else { int l=ma,r=ss; int mid; while(l<=r) { mid=(l+r)/2; if(mid<=ss-mid+1) l=mid+1; else r=mid-1; } printf("%d\n",l); } } return 0; }
- Noj Red packet 1651 (二分)
- Noj Red packet -1651 (二分)
- NOJ 1651 Red packet(二分)
- Noj 1651 Red packet
- [1651] Red packet【二分】
- Red packet (二分)
- 【NBUT】1651 - Red packet(二分)
- 【NBUTOJ】-1651-Red packet(二分)
- NBU:1651 Red packet(二分)【好】
- Red packet 二分
- Red packet【二分】
- Red packet~二分
- Red packet 二分算法
- NUBT 1651 Red packet(红包问题,二分,宁波工程学院在线评测)
- NbUT 1651Red packet
- 【NBUT】[1651]Red packet
- NBUT 1651 Red packet
- NOJ-----1651二分
- 启动项目报错this web application instance has been stopped already.
- form 表单提交不刷新页面
- 最详细的JavaScript和事件解读
- 203. Remove Linked List Elements
- .length .length() .size()的使用方法和区别
- Noj Red packet -1651 (二分)
- PullToRefresh源码分析(I)
- android studio 程序退出提示
- Android资源文件夹名称中的修饰语“sw600dp和sw720dp”等是如何对应到具体设备的?
- Maven依赖机制
- 【HDU 5755】Gambler Bo(高斯消元)
- Parcel了解
- UIView非常用方法及属性详解
- TCP、UDP、RTP(RTCP)异同与区别