Codeforces Round #379 (Div. 2) C. Anton and Making Potions

来源:互联网 发布:阿里云os5.1系统root 编辑:程序博客网 时间:2024/05/01 01:55

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 210 992 4 320 10 404 1510 80
Output
20
Input
20 3 210 992 4 3200 100 4004 15100 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
原创粉丝点击