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.

题意:要求得到至少n个药剂,可以使用两种魔法,一种能够缩短制药时间,一种能瞬间制药,

给你x表示标准制药一个要x秒,给你s表示你的法力值为s

m种第一类类魔法,消耗b点魔法,缩短时间为a秒。

k种第二类魔法,消耗d点魔法,瞬间做出c个药。

两种魔法最多各选一个用,问你最少花多少时间能制得至少n个药剂

由于题目给出的c,d是递增的,所以这题相对比较简单,只要遍历一遍第一类魔法再二分查找一下最大且和不超过s的第二类魔法这样就能确保

找到的是最优解,有点贪心的思想。还有一点要注意的,最优的选择可以不用魔法,或者只用一种魔法,这个要注意一下的。

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
const int M = 2e5 + 20;
ll a[M] , b[M] , c[M] , d[M];
int main()
{
ll n , m , k;
scanf("%I64d%I64d%I64d" , &n , &m , &k);
ll x , s;
scanf("%I64d%I64d" , &x , &s);
for(int i = 0 ; i < m ; i++) {
scanf("%I64d" , &a[i]);
}
for(int i = 0 ; i < m ; i++) {
scanf("%I64d" , &b[i]);
}
for(int i = 0 ; i < k ; i++) {
scanf("%I64d" , &c[i]);
}
for(int i = 0 ; i < k ; i++) {
scanf("%I64d" , &d[i]);
}
ll MIN = n * x;
a[m] = x;
for(int i = 0 ; i <= m ; i++) {
if(s >= b[i]) {
ll temp = s - b[i];
int pos = upper_bound(d , d + k , temp) - d;
if(pos == 0) {
MIN = min(MIN , n * a[i]);
continue;
}
pos--;
ll gg = n - c[pos];
gg *= a[i];
MIN = min(MIN , gg);
}
}
printf("%I64d\n" , MIN);
return 0;
}

Codeforces 734C. Anton and Making Potions(二分)的更多相关文章

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

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

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

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

  4. CodeForces 785C Anton and Fairy Tale 二分

    题意: 有一个谷仓容量为\(n\),谷仓第一天是满的,然后每天都发生这两件事: 往谷仓中放\(m\)个谷子,多出来的忽略掉 第\(i\)天来\(i\)只麻雀,吃掉\(i\)个谷子 求多少天后谷仓会空 ...

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

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

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

  7. [二分] Codefoces Anton and Making Potions

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

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

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

  9. Anton and Making Potions

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

随机推荐

  1. export,export default,module.exports,import,require之间的区别和关联

    module.exports Node 应用由模块组成,采用 CommonJS 模块规范.根据这个规范,每个文件就是一个模块,有自己的作用域.在这些文件里面定义的变量.函数.类,都是私有的,对外不可见 ...

  2. Java性能权威指南读书笔记--之一

    JIT(即时编译) 解释型代码:程序可移植,相同的代码在任何有适当解释器的机器上,都能运行,但是速度慢. 编译型代码:速度快,电视不同CPU平台的代码无法兼容. java则是使用java的编译器先将其 ...

  3. .netcore持续集成测试篇之Xunit数据驱动测试一

    系列目录 Nunit里提供了丰富的数据测试功能,虽然Xunit里提供的比较少,但是也能满足很多场景下使用了,如果数据场景非常复杂,Nunit和Xunit都是无法胜任的,有不少测试者选择自己编写一个数据 ...

  4. linux学习总结--linux100day(day2)

    Linux中的哲学--一切皆文件 为了便于操作,我们可以使用secureCRT或Xshell连接到我们的虚拟机. 要用远程工具连接到虚拟机上,我们只需要打开虚拟机上的ssh服务,在xshell中填写主 ...

  5. JSmooth 将java代码打包成exe

    JSmooth 将java代码打包成exe 前言 java代码写了这么多了,但由于jdk的限制,我只能在jdk电脑上运行项目.所以最近在研究打包exe这个问题,今天终于实现了. JSmooth下载 前 ...

  6. vue组件传值之$attrs、$listeners

    当有父组件A,子组件B,孙子组件C的时候 A-B B-C 的传值想必大家应该都非常熟悉了,通过props和$emit和$on来进行传值 那么A-C之间的传值要怎么做呢? 1.event.bus总线传值 ...

  7. Jenkins持续集成项目搭建——基于Python Selenium自动化测试

    参考链接:https://www.liaoxuefeng.com/article/1083282007018592 第一步:去官网https://jenkins.io/下载最新的war包 第二步:安装 ...

  8. C#.Net实现AutoCAD块属性提取

    https://blog.csdn.net/dengyiyu/article/details/2201175 本文主要给大家介绍一下SmartSoft中用C#.Net实现AutoCAD块属性提取的方法 ...

  9. zuul集成Sentinel最新的网关流控组件

    一.说明 Sentinel 网关流控支持针对不同的路由和自定义的 API 分组进行流控,支持针对请求属性(如 URL 参数,Client IP,Header 等)进行流控.Sentinel 1.6.3 ...

  10. Tomcat源码分析 (七)----- Tomcat 启动过程(二)

    在上一篇文章中,我们分析了tomcat的初始化过程,是由Bootstrap反射调用Catalina的load方法完成tomcat的初始化,包括server.xml的解析.实例化各大组件.初始化组件等逻 ...