Created
November 21, 2022 17:45
-
-
Save qjatn0120/8e2658afb9f479a5e3658db83167b8c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
const int MX = 2e5 + 5; | |
const int MX2 = 2e5; | |
int t, n; | |
long long int arr[MX], sum[MX], c, d; | |
bool test(int k){ | |
long long int days = d; | |
long long int coins = sum[k] * (days / k); | |
days %= k; | |
coins += sum[days]; | |
return coins >= c; | |
} | |
int main(){ | |
cin.tie(nullptr), ios::sync_with_stdio(false); | |
cin >> t; | |
while(t--){ | |
cin >> n >> c >> d; | |
for(int i = 1; i <= n; i++) cin >> arr[i]; | |
for(int i = n + 1; i <= d; i++) arr[i] = 0; | |
sort(arr + 1, arr + n + 1, greater <long long int> ()); | |
for(int i = 1; i <= d; i++) sum[i] = sum[i - 1] + arr[i]; | |
if(!test(1)){ | |
cout << "Impossible\n"; | |
continue; | |
} | |
if(sum[d] >= c){ | |
cout << "Infinity\n"; | |
continue; | |
} | |
int lo = 1, hi = d; | |
while(lo < hi){ | |
int mid = (lo + hi + 1) >> 1; | |
if(test(mid)) lo = mid; | |
else hi = mid - 1; | |
} | |
cout << (lo - 1) << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment