CodeForces

来源:互联网 发布:ps3验证游戏数据 编辑:程序博客网 时间:2024/06/08 16:44

http://codeforces.com/problemset/problem/734/C

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 npotions.

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 nmk (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 210 992 4 320 10 404 1510 80
output
20
input
20 3 210 992 4 3200 100 4004 15100 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 80manapoints. 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件物品要完成,完成每件物品的时间是x。有两种buff。第一种有m个,每个消耗bi法力值,可以使制作时间变为ai。第二种有k个,每个消耗法力值di,可以瞬间完成ci个物品。现在你有s点法力值,每种buff最多只能使用一个。求最少的完成时间。

题解:枚举第一种buff,然后二分搜索s-bi。因为第二种buff的法力值和完成件数是升序的,可以直接进行二分。

代码:

#include<bits/stdc++.h>#define debug cout<<"aaa"<<endl#define mem(a,b) memset(a,b,sizeof(a))#define LL long long#define lson l,mid,root<<1#define rson mid+1,r,root<<1|1#define MIN_INT (-2147483647-1)#define MAX_INT 2147483647#define MAX_LL 9223372036854775807i64#define MIN_LL (-9223372036854775807i64-1)using namespace std;const int N = 200000 + 5;const int mod = 1000000000 + 7;LL a[N],b[N],c[N],d[N];LL n,m,k;LL x,s,fa;int l,r,mid,pos;LL ans,temp;int main(){mem(a,0),mem(b,0),mem(c,0),mem(d,0);scanf("%I64d%I64d%I64d",&n,&m,&k);scanf("%I64d%I64d",&x,&s);ans=x*n;for(int i=1;i<=m;i++){scanf("%I64d",&a[i]);}for(int i=1;i<=m;i++){scanf("%I64d",&b[i]);}for(int i=1;i<=k;i++){scanf("%I64d",&c[i]);}for(int i=1;i<=k;i++){scanf("%I64d",&d[i]);}//加上这个a[0]是,不用第一种buff的情况 a[0]=x,ans=x*n;for(int i=0;i<=m;i++){fa=s-b[i];if(fa<0){continue;}l=0,r=k,pos=k;while(l<=r){mid=(l+r)>>1;if(d[mid]>fa){r=mid-1;}else{pos=mid;l=mid+1;}}temp=(n-c[pos])*a[i];ans=min(ans,temp);}printf("%I64d\n",ans);return 0;}


原创粉丝点击