zoukankan      html  css  js  c++  java
  • Red packet

    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. 

    Output

    Ouput the least money that you need to become the “lucky man”, if it is impossible, output “Impossible” (no quote). 

    Sample Input

    3
    3 5 2
    2 1
    4 10 2
    2 3
    4 15 2
    3 5
    

    Sample Output

    Impossible
    4
    

    6

    #include<cstdio>//这个题用int就可以过  我之前用long  long一直错  可能是该题的网站不支持long long 做题时要注意 
    #include<cstring>
    int  money[100001];
    int main()
    {
    	int t;
    	scanf("%d",&t); 
    	while(t--)
    	{
    		int  n,m,k;
    		scanf("%d%d%d",&n,&m,&k);
    		int  sum=0; 
    		int  max=0;
    		for(int i=0;i<k;i++)
    		{
    			scanf("%d",&money[i]);
    			sum+=money[i];
    			if(max<money[i])
    			{
    				max=money[i];
    			}
    		 } 
    		 int  qian=m-sum;
    		 int  ren=n-k;	
              int  q=qian-ren+1;
    		 
    		if(q<=max)
    		{
    				printf("Impossible
    ");
    		}
    		else
    		{ 
    		int  l=max+1 , r=q;
    			int  mid;
    			while(l<=r)
    			{
    				mid=(l+r)/2;
    				if(mid<=q-mid+1)
    				{
    					l=mid+1;
    				}
    				else
    				{
    					r=mid-1;
    				}
    			}
    				printf("%d
    ",l);
    		}
    	}
    	return 0;
    }


  • 相关阅读:
    金蝶,用友,浪潮erp介绍
    Javascript(Prototype)继承机制的设计思想
    IEnumerator和IEnumerable的关系
    MVC实用构架实战(一)——使用MEF实现IOC
    sql 数字转换为字符串补0
    scrum角色及其职责介绍
    NPOI 名称空间介绍
    双循环排序与冒泡排序的区别
    Silverlight 应用 WCF RIA Services 在 IIS6 部署问题总结
    PD15 数据库反向工程
  • 原文地址:https://www.cnblogs.com/kingjordan/p/12027121.html
Copyright © 2011-2022 走看看