Red packet (二分)

Red packet
Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:

Description

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. 

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>
#include<iostream>
using namespace std;
int main()
{
    int t,n,m,k;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&k);
        int ma = 0 , sum =0;
        int a;
        for(int i = 0 ; i < k ; i++)
        {
            scanf("%d",&a);
            sum += a;
            ma = max(ma,a);
        }
        int s = m - sum;
        int num = n - k -1;
        if(s - num <= ma)
            printf("Impossible\n");
        else{
            int l = ma+1 , r = s - num;
            while(l <= r)
            {
                int mid = (l + r) / 2;
                if(mid <= s - num - mid + 1)
                    l = mid + 1;
                else
                    r = mid - 1;
            }
            printf("%d\n",l);
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Packet filtering是一种网络安全技术,用于检查和控制通过网络的数据包流量。它是一种基于规则的安全控制方法,通过过滤网络数据包,可以实现对网络流量的监控、过滤和防护。 Packet filtering的基本原理是基于预先设定的规则,对网络数据包进行过滤和处理。这些规则由管理员定义,可以包括源IP地址、目标IP地址、目标端口、协议类型等信息。当一个数据包到达时,它会经过这些规则的匹配,如果符合规则,就会被允许通过,否则就会被丢弃或者被转发到其他位置进行处理。 Packet filtering可以用于多种网络安全方案,如防火墙、入侵检测系统、网关路由器等。它可以实现不同的安全策略,如允许进出某些IP地址、端口或协议,限制某些网络流量、防止DDoS攻击等。 Packet filtering的优点包括: 1. 简单易用:Packet filtering是一种基于规则的简单方法,易于理解和配置。 2. 快速高效:Packet filtering是一种高效的方法,可以对大量数据包进行快速过滤和处理。 3. 灵活可控:Packet filtering可以根据需要定义不同的规则,实现灵活的安全控制。 4. 低成本:Packet filtering不需要特殊的硬件或软件支持,可以在现有设备上实现。 5. 支持多种协议:Packet filtering可以支持多种网络协议,如TCP、UDP、ICMP等。 Packet filtering的缺点包括: 1. 无法检测加密流量:Packet filtering无法检测加密的数据流量,因此无法防止加密数据的泄露。 2. 无法处理复杂协议:Packet filtering无法处理复杂的协议,如FTP和H.323等。 3. 容易受到攻击:Packet filtering依赖于规则的正确性和完整性,如果规则设置不当,就会容易受到攻击。 4. 无法检测应用层攻击:Packet filtering只能检测和过滤网络数据包,无法检测和防止应用层攻击。 5. 无法提供完整安全保护:Packet filtering只是网络安全的一种基本方法,无法提供完整的安全保护。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值