Codeforces 734C Anton and Making Potions【二分】

C. Anton and Making Potions
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions.

Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions.

  1. Spells of this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs bi manapoints and changes the preparation time of each potion to ai instead of x.
  2. Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs di manapoints and instantly create ci potions.

Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions.

Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions.

Input

The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·109, 1 ≤ m, k ≤ 2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.

The second line of the input contains two integers x and s (2 ≤ x ≤ 2·109, 1 ≤ s ≤ 2·109) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use.

The third line contains m integers ai (1 ≤ ai < x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used.

The fourth line contains m integers bi (1 ≤ bi ≤ 2·109) — the number of manapoints to use the i-th spell of the first type.

There are k integers ci (1 ≤ ci ≤ n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It's guaranteed that ci are not decreasing, i.e. ci ≤ cj if i < j.

The sixth line contains k integers di (1 ≤ di ≤ 2·109) — the number of manapoints required to use the i-th spell of the second type. It's guaranteed that di are not decreasing, i.e. di ≤ dj if i < j.

Output

Print one integer — the minimum time one has to spent in order to prepare n potions.

Examples
Input
20 3 2
10 99
2 4 3
20 10 40
4 15
10 80
Output
20
Input
20 3 2
10 99
2 4 3
200 100 400
4 15
100 800
Output
200
Note

In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each).

In the second sample, Anton can't use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200.

题目大意:

一共需要做N个物品,其中有类型1的魔法m个,类型2的魔法K个。

如果不使用魔法的情况下,做一个物品需要X的时间。

此时魔法值为S,使用魔法需要消耗对应的魔法值。

类型1的魔法作用为:将物品制作时间减少至ai.需要消耗的魔法值为bi.

类型2的魔法作用为:一瞬间制作出ci个物品,同时消耗魔法值为ci.

要求每种魔法最多只能使用一个。

对应求制作N个物品的最小时间花费。


思路:


1、首先我们可以预处理出:

①不使用任何魔法的时间花费

②只使用类型1的魔法的时间花费

③只使用类型2的魔法的时间花费

然后维护上述三种情况的最小值。


2、那么接下来处理两种魔法各使用一个的情况:

①观察到ci和di都是非递减的,那么我们考虑先枚举类型1的魔法使用哪一个。

②那么肯定这样一个问题:此时这样的情况下,我们肯定是消耗魔法越高越好,因为di是非递减的同时,ci也是非递减的。

③那么我们二分查找剩余的魔法值能够使用的魔法中,最高制作ci的数目。

④那么此时情况的时间花费就已知了,过程维护最小即可。


Ac代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll __int64
ll n,m,k,x,s,output;
struct node
{
    ll bi;
    ll cost;
}one[200060];
struct node2
{
    ll ci;
    ll cost;
}two[200060];
int main()
{
    while(~scanf("%I64d%I64d%I64d",&n,&m,&k))
    {
        scanf("%I64d%I64d",&x,&s);
        output=n*x;
        for(int i=0;i<m;i++)
        {
            scanf("%I64d",&one[i].bi);
        }
        for(int i=0;i<m;i++)
        {
            scanf("%I64d",&one[i].cost);
            if(s>=one[i].cost)
            {
                output=min(output,one[i].bi*n);
            }
        }
        for(int i=0;i<k;i++)
        {
            scanf("%I64d",&two[i].ci);
        }
        for(int i=0;i<k;i++)
        {
            scanf("%I64d",&two[i].cost);
            if(s>=two[i].cost)
            {
                ll tmp=n-two[i].ci;
                if(tmp<0)tmp=0;
                output=min(output,tmp*x);
            }
        }
        for(int i=0;i<m;i++)
        {
            int l=0;
            int r=k-1;
            ll ans=5000000000000000000;
            while(r>=l)
            {
                int mid=(l+r)/2;
                if(two[mid].cost+one[i].cost>s)
                {
                    r=mid-1;
                }
                else
                {
                    ll tmp=n-two[mid].ci;
                    if(tmp<0)tmp=0;
                    ans=min(ans,tmp*one[i].bi);
                    l=mid+1;
                }
            }
            output=min(output,ans);
        }
        printf("%I64d\n",output);
    }
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值