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

分析:枚举第一种,二分第二种,因为单调不减;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,a[maxn],b[maxn],c[maxn],d[maxn],x,s;
ll ans;
int main()
{
int i,j;
scanf("%d%d%d%d%d",&n,&m,&k,&x,&s);
ans=(ll)x*n;
rep(i,,m)a[i]=read();
rep(i,,m)b[i]=read();
rep(i,,k)c[i]=read();
rep(i,,k)d[i]=read();
a[]=x;
rep(i,,m)
{
if(s>=b[i])
{
int pos=upper_bound(d,d+k+,s-b[i])-d-;
ans=min(ans,(ll)min(x,a[i])*max(,n-c[pos]));
}
}
printf("%lld\n",ans);
//system("Pause");
return ;
}

Anton and Making Potions的更多相关文章

  1. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

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

  3. Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分

    题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 s ...

  4. 二分算法题目训练(三)——Anton and Making Potions详解

    codeforces734C——Anton and Making Potions详解 Anton and Making Potions 题目描述(google翻译) 安东正在玩一个非常有趣的电脑游戏, ...

  5. [二分] Codefoces Anton and Making Potions

    Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input sta ...

  6. CodeForce-734C Anton and Making Potions(贪心+二分)

    CodeForce-734C Anton and Making Potions  C. Anton and Making Potions time limit per test 4 seconds m ...

  7. 【13.77%】【codeforces 734C】Anton and Making Potions

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. Codeforces 734C. Anton and Making Potions(二分)

    Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass ...

  9. Codeforces 734C Anton and Making Potions(枚举+二分)

    题目链接:http://codeforces.com/problemset/problem/734/C 题目大意:要制作n个药,初始制作一个药的时间为x,魔力值为s,有两类咒语,第一类周瑜有m种,每种 ...

随机推荐

  1. Web安全知多少

    随着Web2.0.网络社交等一系列新型的互联网产品的诞生,基于Web环境的互联网应用越来越广泛,企业信息化的过程中,越来越多的应用都架设在Web平台上.Web业务的迅速发展吸引了黑客们的强烈关注,接踵 ...

  2. hdu和poj的基础dp30道

    题目转自:https://crazyac.wordpress.com/dp%E4%B8%93%E8%BE%91/ 1.hdu 1864 最大报销额 唔,用网上的算法连自己的数据都没过,hdu的数据居然 ...

  3. POJ 2599 A funny game#树形SG(DFS实现)

    http://poj.org/problem?id=2599 #include<iostream> #include<cstdio> #include<cstring&g ...

  4. hdu2141AC代码分享

    #include <iostream> #include <algorithm> using namespace std; const int N = 505; /////// ...

  5. bug记录_document.defaultview.getcomputedstyle()

    页面中使用document.defaultview.getcomputedstyle()在火狐下取不到值. 原本方法现在$(document).ready()中,换到window.onload里就可以 ...

  6. 朱丽叶—Cuda+OSG

    #include <cuda_runtime.h> #include <osg/Image> ; typedef struct cuComplex { float r; flo ...

  7. TortoiseGit - pull 与 fetch

    Git的Pull其实是fetch与Merge两个命令的合并. 平时遇到的问题是,在本地分支进行了一些修改,准备提交.但是怕提交前有其他人push了新的代码.于是想在提交前,看看远程仓库上的log.这时 ...

  8. Java 水仙花数

    小小练习大神掠过吧 题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数&quo ...

  9. Excel补全日期(日期按顺序补全)

    1.给出的数据 2.想补全缺失的日期,比如2015/3/1,2015/3/2,... 1)在D列输入完整的日期,如下图所示: 2)在E2处写函数“=IF(ISERR(VLOOKUP(D2,B:C,2, ...

  10. Python 学习笔记12

    不积跬步,无以至千里.不积小流,无以成江河. 当我觉得沮丧.绝望的时候,就疯狂的敲代码,这样会好受一点. 今天和昨天敲了两天的小程序,算是对python的具体语法规则有个初步的手熟. http://w ...