最后的情况一定是第一个人有a[1]+mid票 其他人最多有a[1]+mid-1张票。算出刚开始的sum(a[2]+a[3]+`````a[n]) 每次投票 有个水军投1号,剩m-1张票投其他人。那么一定满足
(a[1]+mid-1)*(n-1)-sum>=(m-1)*mid 前面的代表剩下n-1个人最多的票数 然后(m-1)*mid是mid轮投票之后添加的票数。
二分求这个mid就好了
由于没有oj地址 所以没测过 但思路应该是这样啦
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define pi acos(-1)
#define endl '\n'
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0);
#define rand() srand(time(0));
typedef long long LL;
typedef pair<int, int> pii;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
//const int dx[]={-1,0,1,0,-1,-1,1,1};
//const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=1e5+100;
const double EPS=1e-9;
const int MOD=1000000007;
#define mod(x) ((x)%MOD);
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;
/*lch[root] = build(L1,p-1,L2+1,L2+cnt);
rch[root] = build(p+1,R1,L2+cnt+1,R2);中前*/
/*lch[root] = build(L1,p-1,L2,L2+cnt-1);
rch[root] = build(p+1,R1,L2+cnt,R2-1);中后*/
long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}
int a[maxx];
int n,m,sum;
int check(int x)
{
int cnt=a[1]+x-1;
if((cnt*(n-1)-sum)>=(m-1)*x)
return 1;
else return 0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
sum=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(i==1)
continue;
sum+=a[i];
}
int l=0,r=INF;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid))
r=mid-1;
else l=mid+1;
}
if(check(l))
cout<<l<<endl;
else puts("Impossible");
}
}