Code: Flip Flops
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
ll c, k;
cin >> n >> c >> k;
vector<ll> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a.begin(), a.end());
ll sum = 0;
for (int i = 0; i < n; ++i) {
ll upper = c + sum;
if (a[i] > upper)
break;
ll x = min(upper, a[i] + k);
k -= (x - a[i]);
sum += x;
}
cout << c + sum << '\n';
}
return 0;
}