Codeforces Round #379 (Div. 2) C. 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 preparen 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 costsbi manapoints and changes the preparation time of each potion toai instead ofx.
  2. Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costsdi manapoints and instantly createci potions.

Anton can use no more than one spell of the first type andno more than one spell of the second type, and the total number of manapoints spent should not exceeds. 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 leastn 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 ands (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 thei-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 thei-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 thei-th spell of the second type is used. It's guaranteed thatci arenot decreasing, i.e. ci ≤ cj ifi < j.

The sixth line contains k integers di (1 ≤ di ≤ 2·109) — the number of manapoints required to use thei-th spell of the second type. It's guaranteed thatdi arenot decreasing, i.e. di ≤ dj ifi < 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



思路:由于第二种药剂的单调性,我们可以枚举第一种药剂然后二分第二种药剂的选择(mp的选择)。这样就可以做到在nlogn的时间内解决。

注意考虑边界情况。

其实就算第二种药剂没有单调性,也可以强行转换成有单调性的,毕竟一种药剂只能使用一次。


代码链接:

#include <bits/stdc++.h>

using namespace std;
const int maxn=1e6+5;
int secondmp[maxn],secondans[maxn];
int firstmp[maxn],firstans[maxn];
int main()
{
    int n,m,k,x,s;
    scanf("%d %d %d",&n,&m,&k);
    scanf("%d %d",&x,&s);
    for(int i=1;i <= m;i++ )
    {
        scanf("%d",&firstans[i]);
    }
    for(int i=1;i <= m;i++ )
    {
        scanf("%d",&firstmp[i]);
    }
    for(int i=1;i <= k;i++ )
    {
        scanf("%d",&secondans[i]);
    }
    for(int i=1;i <= k;i++ )
    {
        scanf("%d",&secondmp[i]);
    }
    long long ans=1LL*n*x;
    firstans[0]=x;
    for(int i=0;i<=m;i++)
    {
        if(s-firstmp[i]<0) continue;

        int now=upper_bound(secondmp,secondmp+k+1,s-firstmp[i])-secondmp;

        now--;

        long long nowans=1LL*(n-secondans[now])*firstans[i];

        ans=min(ans,nowans);
    }
    cout<<ans<<endl;
    return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值