题意比较难以描述,故略;
考虑到用k个如果成立,那么k+1觉得成立。因而可以想到二分。考虑贡献时,先上a,b的lcm,在上max(a,b),最后上min(a,b)
两个2e5数的lcm有可能爆int,需要注意。
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
const int N =2e5 +10;
int p[N],x,y,a,b,n,q;
LL k,lc;
int gcd(int xx,int yy){
return !yy ? xx : gcd (yy ,xx % yy);
}
LL lcm(int xx,int yy){
return (LL)xx * yy / gcd(xx,yy);
}
int check(int num){
int num1 = (LL)num / lc;
int num2 = num / a;
int num3 = num / b;
LL tot = 0;
int i = 0;
for(;i < num1 && i < n;i ++) tot += (LL)(x + y) * p[i];
for(int cnt = 0 ; i < n && cnt < num2 - num1 ; i++ ,cnt++) tot += (LL)x * p[i];
for(int cnt = 0 ; i < n && cnt < num3 - num1 ; i++ ,cnt++) tot += (LL)y * p[i];
//cout<<num<<' '<<num1<<' '<<num2<<' '<<num3<<' '<<tot<<endl;
return tot >= k;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
cin>>q;
while(q--){
cin>>n;
for(int i = 0 ;i < n ;i ++) {
cin>>p[i];
p[i] /= 100;
}
sort(p,p+n);
reverse(p,p+n);
cin>>x>>a>>y>>b>>k;
if(x < y) swap(x,y),swap(a,b);
lc = lcm(a,b);
int flag = 0 ;
int l = 1, r = n ;
while(l <= r){
int mid = (l + r) / 2;
if(check(mid)) flag = 1, r = mid - 1;
else l = mid + 1;
}
if(flag) cout<<l<<endl;
else cout<<-1<<endl;
}
return 0;
}