题目大意:有n个药剂需要制作,制作每个药剂需要x秒钟,并且最初有m的能量;魔法师现在有两种催化剂,第一种可以消耗cost1[i]的能量,使得所有药剂的所需时间变为a[i];第二种也是消耗能量,使得b[i]个数的药剂瞬间制作好;但两种催化剂每种只能最多选择一种,问最后最少需要多少时间;
题目解析:首先我们将试剂1按照cost升序,遍历一遍,便利的时候二分当前剩余能量在第二种试剂可以获得的最大收益(因为第二种试剂随着cost提高,他们的效益也提高,所以可以二分),注意因为最多一个,所以每一种试剂一开始我们需要添加一个不选的元素;这样就能在O(nlogn)跑出来;
AC代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
struct node1
{
__int64 a,cost;
}s[200010];
struct node2
{
__int64 b,cost;
}q[200010];
bool cmp(node1 a,node1 b)
{
return a.cost<b.cost;
}
int main()
{
int n,m,k,i;
__int64 ans,x,ss,sum,temp;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
scanf("%I64d%I64d",&x,&ss);
ans=x*n;
for(i=1;i<=m;i++)
scanf("%I64d",&s[i].a);
for(i=1;i<=m;i++)
scanf("%I64d",&s[i].cost);
for(i=1;i<=k;i++)
scanf("%I64d",&q[i].b);
for(i=1;i<=k;i++)
scanf("%I64d",&q[i].cost);
s[0].a=x;
s[0].cost=0;
q[0].b=0;
q[0].cost=0;
m++;
k++;
sort(s,s+m,cmp);
for(i=0;i<m;i++)
{
temp=ss-s[i].cost;
if(temp<0)
break;
int l=0,r=k-1,pos;
while(l<=r)
{
int mid=(l+r)/2;
if(q[mid].cost<=temp)
{
pos=mid;
l=mid+1;
}
else
{
r=mid-1;
}
}
sum=(n-q[pos].b)*s[i].a;
ans=min(ans,sum);
}
printf("%I64d\n",ans);
}
return 0;
}