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.
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
Hint
无
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 100010;
int main(){
int T; scanf("%d",&T);
while(T--){
int a[maxn],ans,n,m,k,MAX = 0;//n人,m元,k份,ans还剩的钱;
memset(a,0,sizeof(a));
scanf("%d%d%d",&n,&m,&k);
ans = m;
for(int i = 1; i <= k; ++i){
scanf("%d",&a[i]);//每个分过的人分到的钱;
ans -= a[i];
}
sort(a+1,a+1+k);
MAX = max(MAX,a[k]);
int l,r;
if(n - k == 1){
l = r = ans;
}
else{
if(n - k == ans){
r = 0;
}
else{
l = (ans - (n-k-2))/2 + 1;
r = ans-(n-k-1);
}
}
l = max(l,MAX+1);
if(l <= r){
printf("%d\n",l);
}
else{
printf("Impossible\n");
}
}
return 0;
}