[CodeForces-1760F]

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值