There are �n quests. If you complete the �i-th quest, you will gain ��ai coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for �k days. (For example, if �=2k=2 and you do quest 11 on day 11, then you cannot do it on day 22 or 33, but you can do it again on day 44.)
You are given two integers �c and �d. Find the maximum value of �k such that you can gain at least �c coins over �d days. If no such �k exists, output Impossible. If �k can be arbitrarily large, output Infinity.
Input
The input consists of multiple test cases. The first line contains an integer �t (1≤�≤1041≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers �,�,�n,c,d (2≤�≤2⋅1052≤n≤2⋅105; 1≤�≤10161≤c≤1016; 1≤�≤2⋅1051≤d≤2⋅105) — the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains �n integers �1,�2,…,��a1,a2,…,an (1≤��≤1091≤ai≤109) — the rewards for the quests.
The sum of �n over all test cases does not exceed 2⋅1052⋅105, and the sum of �d over all test cases does not exceed 2⋅1052⋅105.
Output
For each test case, output one of the following.
- If no such k exists, output Impossible.
- If k can be arbitrarily large, output Infinity.
- Otherwise, output a single integer — the maximum value of �k such that you can gain at least c coins over �d days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
#include<bits/stdc++.h>
#define Acode ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
#define endl '\n'
ll n, c, d;
const int N = 3e5 + 10;
int a[N];
bool check(ll mid)
{
int k = 0;
ll sum = 0;
for (int i = 1; i <= d; i++)
{
k++;
if (k <= n)
{
sum += a[k];
}
if (k == mid + 1)k = 0;
}
if (sum < c)return false;
else return true;
}
int main()
{
Acode;
int t;
cin >> t;
while (t--)
{
cin >> n >> c >> d;
ll sum = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
//sum += a[i];
}
sort(a + 1, a + 1 + n, greater<ll>());
for (int i = 1; i <= min(n,d); i++)
{
sum += a[i];
}
if (sum >= c)
{
cout << "Infinity\n";
continue;
}
if (d * a[1] < c)
{
cout << "Impossible\n";
continue;
}
ll l = 0, r = N;
while (l <= r)
{
ll mid = l + r >> 1;
if (check(mid)) l = mid + 1;
else r = mid - 1;
}
cout << r << endl;
}
return 0;
}