NOJ-----1651二分
来源:互联网 发布:php搜索功能代码源码 编辑:程序博客网 时间:2024/05/11 21:07
I - Red packet
Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64uDescription
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
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.
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.
Output
Ouput the least money that you need to become the “lucky man”, if it is impossible, output “Impossible” (no quote).
Sample Input
33 5 22 14 10 22 34 15 23 5
Sample Output
Impossible46
就是发红包,给出总钱数n,总人数m,已经k个已经拿到钱的人和他们拿到的钱,问把钱全分完,每个人最少拿1块钱,所有人拿到的钱都比这个人少,这个人最少拿多少钱
#include<cstdio>#include<cmath>#include<algorithm>using namespace std;int main(){int s, e, m, m1, v, n, k, u, ans, last, cnt, t;scanf("%d", &t);while(t--){scanf("%d%d%d", &n, &m1, &k);ans = u = 0;for(int i = 0; i < k; i++){scanf("%d", &v);u = u > v ? u : v;ans += v;}s = u+1;//必须比前k个人拿钱最多的那个多e = cnt = m1 - ans - n + k + 1;//剩下的每人先按1块钱算,除掉自己if(u >= e){printf("Impossible\n");continue;}else{while(s <= e){m = (e+s) >> 1;if(m <= cnt - m + 1){s = m+1;}else{e = m-1;}}printf("%d\n", s);}}return 0;}
0 0
- NOJ-----1651二分
- Noj Red packet 1651 (二分)
- Noj Red packet -1651 (二分)
- NOJ 1651 Red packet(二分)
- NWPU-NOJ-二分查找
- 二分 NOJ 1567
- NOJ 1001 二分查找
- NOJ 1616Music Notes 二分
- 二分枚举 +贪心 NOJ 680 摘枇杷
- 二分 最大值最小化||最小值最大化 NOJ 1133
- 算法练习-NOJ-1001-二分查找
- noj算法题——二分查找
- Noj 1651 Red packet
- Noj
- NOJ——1649Find Sum(二分查找)
- NOJ(1001)-递归与分治算法-二分查找
- NOJ 176
- NOJ 175
- Matlab和simulink仿真轮式机器人防撞
- 旋转数组的最小数字
- codevs1907方格取数最大流
- 虚拟机的类加载机制
- 给大家推荐一个.Net的混淆防反编译工具ConfuserEx
- NOJ-----1651二分
- MySQL基础(三)
- Cannot make a static reference to the non-static field
- Android Bundle类
- iOS原生App与H5页面交互 离线缓存 笔记
- Pro JPA2读书笔记系列(八)-第八章(查询语言)
- 浪潮集团入职技术培训(二)
- 图论500题
- [Linux] 管道容量以及缓冲区的组成