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 n 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 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

Copy
20 3 2
10 99
2 4 3
20 10 40
4 15
10 80
output

Copy
20
input

Copy
20 3 2
10 99
2 4 3
200 100 400
4 15
100 800
output

Copy
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 80 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.

题意:

有n瓶药,一开始做这n瓶药每瓶需要x的时间,现在有s块钱,并有两种魔法,每种魔法最多只能用一次(也就是说可用不用,这是坑点,要注意no more,at least之类的)
第一种魔法是把所有药的准备时间变为ai,花费是bi,第二种魔法是用0秒时间立刻做出ci个药,花费是di,注意input那指出第二种魔法的ci和di是非严格递增的

思路:

看到递增就想到了二分,所以就枚举第一种魔法,同时二分第二种魔法,复杂度O(mlogk),注意要单独算出两种魔法都不用,只用第一种魔法和只用第二种魔法的情况,这是本题的坑点

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int amn=2e5+;
ll a[amn],b[amn],c[amn],d[amn],ans,l,r,mid,rm,rn;
int main(){
///注意:可用只用第一种魔法,或只用第二种魔法,或两种魔法各用一个
ll n,m,k,x,s;
ios::sync_with_stdio();
cin>>n>>m>>k>>x>>s; ///n毒药数量,m第一个,k第二个,x初始时间,s初始钱
for(int i=;i<=m;i++)cin>>a[i]; ///改变时间
for(int i=;i<=m;i++)cin>>b[i]; ///timecost
for(int i=;i<=k;i++)cin>>c[i]; ///立刻做多少
for(int i=;i<=k;i++)cin>>d[i]; ///docost
ans=n*x;
for(int i=;i<=k;i++){
if(s-d[i]<)continue;
ans=min(ans,(n-c[i])*x);
}
for(int i=;i<=m;i++){
rm=s-b[i];
if(rm<)continue;
ans=min(ans,n*a[i]);
l=,r=k;
mid=(l+r)>>;
while(l<=r){
if(d[mid]>rm)r=mid-;
else l=mid+;
mid=(l+r)>>;
}
rn=max(n-c[mid],0ll);
ans=min(ans,rn*a[i]);
// cout<<rm<<' '<<rn<<' '<<b[i]<<' '<<l<<' '<<r<<' '<<c[l]<<' '<<c[r]<<endl;
}
printf("%lld\n",ans);
}
/***
有n瓶药,一开始做这n瓶药每瓶需要x的时间,现在有s块钱,并有两种魔法,每种魔法最多只能用一次(也就是说可用不用,这是坑点,要注意no more,at least之类的)
第一种魔法是把所有药的准备时间变为ai,花费是bi,第二种魔法是用0秒时间立刻做出ci个药,花费是di,注意input那指出第二种魔法的ci和di是非严格递增的
看到递增就想到了二分,所以就枚举第一种魔法,同时二分第二种魔法,复杂度O(mlogk),注意要单独算出两种魔法都不用,只用第一种魔法和只用第二种魔法的情况,这是本题的坑点
***/

[二分] Codefoces 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. CodeForce-734C Anton and Making Potions(贪心+二分)

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

  6. Anton and Making Potions

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

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

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

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

  9. C. Anton and Making Potions 贪心 + 二分

    http://codeforces.com/contest/734/problem/C 因为有两种操作,那么可以这样考虑, 1.都不执行,就是开始的答案是n * x 2.先执行第一个操作,然后就会得到 ...

随机推荐

  1. Go技术日报(2020-02-28)

    go 语言中文网(每日资讯)_2020-02-28 一.Go 语言中文网 Gopher 学习效率低怎么办?曹大谈工程师应该怎么学习 Go 的 http 包中默认路由匹配规则 [每日一库]Web 表单验 ...

  2. Leetcode 24题 两两交换链表中的节点(Swap Nodes in Pairs))Java语言求解

    题目描述: 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表. 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换. 示例: 给定 1->2->3->4,你应该返回 ...

  3. 2、【Spark】Spark环境搭建(集群方式)

    Spark集群方式搭建结构如图所示,按照主从方式.

  4. IT从业者疫情之下出路何在

    作为一个IT行业十年经历的从业人员,在北京大公司工作过,但因衡量着北京大都市的繁华下高消费和高房价,选择到二线城市发展和组建家庭,由此逃离北上广,结束了数年的北漂生涯.很荣幸到了二线城市顺利遇见属于自 ...

  5. Mysql5.7.25安装步骤

    安装步骤 在官网下载mysql-5.7.25-winx64.zip压缩包到本地,解压到非中文目录. 列如(D:\Program Files\mysql-5.7.25-winx64). 在环境变量中添加 ...

  6. 一位资深程序员大牛推荐的Java技术学习路线图

    Web应用,最常见的研发语言是Java和PHP. 后端服务,最常见的研发语言是Java和C/C++. 大数据,最常见的研发语言是Java和Python. 可以说,Java是现阶段中国互联网公司中,覆盖 ...

  7. 从头认识js-基本概念(关键字,保留字,数据类型)

    语法 ECMAScript的语法大量借鉴了C及其他类C语言(如Java和Perl)的语法.因此,熟悉这些语言的开发人员在接受ECMSAScript更加宽松的语法时,一定会有一种轻松自在的感觉. 区分大 ...

  8. 跟我猜Spring-boot:依赖注入

    依赖注入 引&目标 本篇是<跟我猜Spring-Boot>系列的第二篇(Oh,我竟然已经写了10篇了,真不容易). 在上一篇中,我们实现了Bean的创建,但是仅仅是创建而已,并没有 ...

  9. 快速上手 Python 命令行模块 Click

    关于Click? 说下 Click 模块是干啥的,简单说,它就是把我们的 Python 脚本的一些函数,通过 添加带有 Click 关键字的装饰器进行装饰进而将函数调用的形式转化为命令行传参的形式然后 ...

  10. vue中eslint报错的解决方案

    1,Newline required at end of file but not found. (eol-last) //文末需要一行 这个是报错: 这个是不报错的: 只需要在最后一行加上一空行即可 ...