https://codeforces.com/contest/1972/problem/C
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
typedef vector<long long> VI;
#define int long long
#define INF 0x3f3f3f3f
#define endl '\n'
#define N 200010
const int mod = 1e9 + 7;
ll ksm(ll a, ll b) {
ll ans = 1;
for (; b; b >>= 1LL) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x) {
return -x & x;
}
int p[N], si[N];
int find(int x) {
if (x == p[x])return p[x];
p[x] = find(p[x]);
return p[x];
}
//size[find(b)] += size[find(a)];
//p[find(a)] = find(b);
int n, k;
vector<int> a(N);
int check(int x) { //二分判断k能否满足分配后ai均大于等于x
int need = 0;
for (int i = 1; i <= n; i ++) {
if (a[i] < x)need += x - a[i];
}
return need <= k;
}
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; i ++)cin >> a[i];
int l = 0, r = 2e12;
int mx = 0;
while (l + 1 < r) { // 二分找最大的最低分配后的值
int mid = (l + r) / 2;
if (check(mid))l = mid;
else r = mid;
}
if (check(l))mx = l;
else mx = r;
for (int i = 1; i <= n; i ++) {
if (a[i] < mx) {
int t = mx - a[i];
a[i] += t;
k -= t;
}
}
int num = 0;
for (int i = 1; i <= n ; i ++) {
if (a[i] == mx && k) {
a[i] ++;
k --;
}
if (a[i] > mx)num ++;
}
// 1 2 3 4 1 2 3 4 1 2 3 4
int res = 1 + (mx - 1) * n + num; //贪心算排列数 1 + (mx - 1) * n + 多出来数的种类数
cout << res << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T --)
solve();
return 0;
}