Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1)C. Save the Nature
题意:一批商品,位置为a的倍数和b的倍数可以获利,问最少几个商品出售可以获利k
做法:对答案二分,即需要多少个上可以达到k,对这种情况下进行最优check
为什么每次二分都想不到二分。。。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<queue>
#include<map>
#define ll long long
#define pb push_back
#define rep(x,a,b) for (int x=a;x<=b;x++)
#define repp(x,a,b) for (int x=a;x<b;x++)
#define W(x) printf("%d\n",x)
#define WW(x) printf("%lld\n",x)
#define pi 3.14159265358979323846
#define mem(a,x) memset(a,x,sizeof a)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
using namespace std;
const int maxn=2e6+7;
const int INF=1e9;
const ll INFF=1e18;
int p[maxn];
vector<int > V;
bool cmp(int a,int b){return a>b;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main()
{
int t,x,y,n;ll k,sum,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
rep(i,1,n){scanf("%d",&p[i]);p[i]/=100;}
sort(p+1,p+1+n,cmp);
scanf("%d%lld",&x,&a);scanf("%d%lld",&y,&b);scanf("%lld",&k);
ll g=gcd(a,b);
ll lcm=a*b/g;
int l=1,r=n,j=0;
while(l<=r)
{
int mid=(l+r)>>1;
bool mark=false;
V.clear();
sum=0;
for (int i=1;i<=mid;i++)
//由于其他位置是没有获利的,所以只加倍数即可
{
if (i%lcm==0)V.pb(x+y);
else if (i%a==0)V.pb(x);
else if (i%b==0)V.pb(y);
}
sort(V.begin(),V.end(),cmp);
int sz=V.size();
for (int i=0;i<sz;i++)
{
sum+=p[i+1]*V[i];
if (sum>=k){mark=true;j=mid;}
}
if (mark) r=mid-1;
else l=mid+1;
}
if (j==0) W(-1);
else W(j);
}
return 0;
}