鏈接:https://codeforces.com/contest/1223/problem/C
題意:題意好難描述吶,就是給你n張票,你可以改變他們的順序,然後有x,a,y,b你必須按順序選一些票讓他達到k,只能選a,b的整數倍,能得x%,y%的錢,問你最少需要多少張票。
(雖然這場div2被鴿了,晚上十一點打到一點的比賽,但是作爲一個owl,還是打的不亦樂乎。)
解題思路:從一開始想貪心做但是寫了一半回頭看題發現並不能做到,然後看了一眼廣大羣友,有人說二分,頓時恍然大悟,把剛自己刪掉的貪心有撤銷了,把他放到check函數裏二分。。。。然鵝中途竟然因爲該死的變主參數導致debug了半天,哇,長達一個小時我就在那裏ctrl shift +n ,ctrl shift +k,非常酷,巨大的debug經驗,在外部函數裏想變參量一定要重新設參數。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+9;
typedef long long ll;
ll p[maxn];
int n;
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
bool cmp(ll a,ll b)
{
return a>b;
}
ll x,y,a,b,k,temp;
bool check(int n)
{
// cout<<"mid=="<<n<<endl;
ll ans=0;
int num1=n/temp;
// if(a>b)swap(a,b);
int num2=n/a-num1;
int num3=n/b-num1;
int xx=x,yy=y;
// cout<<"yx="<<y<<" "<<x<<endl;
// cout<<"num "<<num1<<" "<<num2<<" "<<num3<<endl;
if(yy>xx)
{
swap(num2,num3);
swap(xx,yy);
}
// cout<<"yx="<<y<<" "<<x<<endl;
// cout<<"num "<<num1<<" "<<num2<<" "<<num3<<endl;
for(int i=0;i<n;i++)
{
if(num1)
{
ans=ans+p[i]*(xx+yy);
num1--;
// cout<<"debug="<<p[i]<<" "<<x<<" "<<y<<endl;
continue;
}
if(num2)
{
ans+=p[i]*xx;
num2--;
// cout<<"x=="<<p[i]<<" "<<x<<endl;
continue;
}
if(num3)
{
ans+=p[i]*yy;
// cout<<"y=="<<p[i]<<" "<<y<<endl;
num3--;
continue;
}
}
// cout<<"ans=="<<ans<<endl;
if(ans>=k)
{
// cout<<"fuck"<<endl;
return true;
}
// cout<<"qqq"<<endl;
return false;
}
int main()
{
// cout<<90*100/gcd(100,90)<<endl;
int q;
cin>>q;
while(q--)
{
memset(p,0,sizeof p);
cin>>n;
for(int i=0;i<n;i++)
{
cin>>p[i];
p[i]/=100ll;
}
cin>>x>>a;
cin>>y>>b;
cin>>k;
temp = a*b/gcd(a,b);
sort(p,p+n,cmp);
// cout<<"temp=="<<temp<<endl;
// int ans=0;
int l=0,r=n;int ans=-1;
while(l<=r)
{
int mid=l+r>>1;
if(check(mid)) {
ans=mid, r=mid-1;
}
else{
l=mid+1;
}
}
cout<<ans<<endl;
}
return 0;
}