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.
- 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.
- 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.
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.
Print one integer — the minimum time one has to spent in order to prepare n potions.
20 3 2 10 99 2 4 3 20 10 40 4 15 10 80
20
20 3 2 10 99 2 4 3 200 100 400 4 15 100 800
200
In the first sample, the optimum answer is to use the second spell of the first type that costs10 manapoints. Thus, the preparation time of each potion changes to4 seconds. Also, Anton should use the second spell of the second type to instantly prepare15 potions spending80 manapoints. The total number of manapoints used is10 + 80 = 90, and the preparation time is4·5 = 20 seconds (15 potions were prepared instantly, and the remaining5 will take4 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 is20·10 = 200.
思路:枚举第一种spell(包括不用的情况),二分找第二种spell的最优解(利用upper_bound函数实现)。
#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
#define REPP(i,k,n) for(int i=k;i<=n;i++)
#define scan(d) scanf("%d",&d)
#define scann(n,m) scanf("%d%d",&n,&m)
#define mst(a,k) memset(a,k,sizeof(a));
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define mod 1000000007
#define N 200005
#define M 15
#define ff first
#define ss second
using namespace std;
int a[N],b[N],c[N],d[N];
main()
{
int n,m,k;
int x,s;
scanf("%d%d%d%d%d",&n,&m,&k,&x,&s);
REP(i,0,m) scan(a[i]);
REP(i,0,m) scan(b[i]);
REP(i,0,k) scan(c[i]);
REP(i,0,k) scan(d[i]);
LL ans = 1LL * x * n; //可能不用两种spell
int it = upper_bound(d , d+k , s) - d - 1;
if(it >= 0) ans = min(ans , 1LL *(n-c[it])* x); //可能不用第二种spell
REP(i,0,m){ //枚举第一种spell
if(s < b[i]) continue; //如果所需 法力值 超出,则跳过
int it = upper_bound(d , d+k, s - b[i]) - d -1;
int tmp = it>=0?n-c[it]:n;
ans = min(ans,1LL * a[i] *tmp );
}
printf("%lld\n",ans);
}