CodeForce-734C Anton and Making Potions
 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 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 spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15potions 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.

 枚举第一种 spell 用了哪一个(注意可能不用),然后观察到第二种 spell 的收益随着代价增大而增大,尽量选代价最大的,二分即可。

  1 #include<map>
2
3 #include<set>
4
5 #include<stack>
6
7 #include<cmath>
8
9 #include<queue>
10
11 #include<bitset>
12
13 #include<math.h>
14
15 #include<vector>
16
17 #include<string>
18
19 #include<stdio.h>
20
21 #include<cstring>
22
23 #include<iostream>
24
25 #include<algorithm>
26
27 #pragma comment(linker, "/STACK:102400000,102400000")
28
29 using namespace std;
30
31 typedef double db;
32
33 typedef long long ll;
34
35 typedef unsigned int uint;
36
37 typedef unsigned long long ull;
38
39 const db eps=1e-5;
40
41 const int N=2e5+10;
42
43 const int M=4e6+10;
44
45 const ll MOD=1000000007;
46
47 const int mod=1000000007;
48
49 const int MAX=1000000010;
50
51 const double pi=acos(-1.0);
52
53 ll a[N],b[N],c[N],d[N];
54
55 int main()
56
57 {
58
59 int i,m,k,l,r,mid;
60
61 ll n,x,s,t,ans;
62
63 scanf("%I64d%d%d", &n, &m, &k);
64
65 scanf("%I64d%I64d", &x, &s);
66
67 for (i=1;i<=m;i++) scanf("%I64d", &a[i]);
68
69 for (i=1;i<=m;i++) scanf("%I64d", &b[i]);
70
71 for (i=1;i<=k;i++) scanf("%I64d", &c[i]);
72
73 for (i=1;i<=k;i++) scanf("%I64d", &d[i]);
74
75
76 ans=n*x;
77
78 for (i=1;i<=k;i++)
79
80 if (d[i]<=s) ans=min(ans,x*max(0ll,n-c[i]));
81
82
83 for (i=1;i<=m;i++)
84
85 if (b[i]<=s&&a[i]<x) {
86
87 t=s-b[i];
88
89 if (t<d[1]) ans=min(ans,n*a[i]);
90
91 else {
92
93 l=1;r=k+1;mid=(l+r)>>1;
94
95 while (l+1<r)
96
97 if (d[mid]<=t) l=mid,mid=(l+r)>>1;
98
99 else r=mid,mid=(l+r)>>1;
100
101 ans=min(ans,max(0ll,n-c[l])*a[i]);
102
103 }
104
105 }
106
107 printf("%I64d\n", ans);
108
109 return 0;
110
111 }

CodeForce-734C Anton and Making Potions(贪心+二分)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  8. [二分] Codefoces Anton and Making Potions

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

  9. Anton and Making Potions

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

随机推荐

  1. git的实用命令(撤回,合并)

    前言 在用开发项目的时候,经常会写着写着会发现写错的时候,人生没有后悔药,但是git有啊,大不了从头再来嘛. git的一些撤销操作 代码还没有存到暂存区 当我们修改了一个文件,还没有执行git add ...

  2. Lingoes安装词典和语音库

    安装词典: 选项->词典,出现"词典管理"窗体,点"安装",从磁盘上选择要安装的词典文件(扩展名为ld2的文件),勾选"添加到索引组" ...

  3. 修改Linux系统的默认语言编码集

    RedHat 今天晚上发现服务器上vi的界面提示变成了乱码,只能将XShell的编码改为GBK才能正常显示,导致consolas字体无法使用,GBK编码下的字体丑陋无比,无法忍受,一轮google之后 ...

  4. Git 使用revert回滚已提交的commit

    在git使用中如果提交错误的代码至远程服务器,可以使用git revert 命令回滚单次commit并且不影响其他commit. 回滚最新一次的提交记录: git revert HEAD 回滚前一次的 ...

  5. 0基础学小程序----day1

    17的书,那时候微信小程序开发程序还是v0.01 19年都v1.02了.位置都不一样了,枯了 技术准备:WXML使用方法类似于HTML,(都不会) 自己的样式语言WXSS兼容了CSS(都不会) 使用J ...

  6. Java基础技术多线程与并发面试【笔记】

    Java基础技术多线程与并发 什么是线程死锁? ​死锁是指两个或两个以上的进程(线程)在执行过程中,由于竞争资源或者由于彼此通信而造成的一种阻塞的现象,若无外力作用,它们都将无法推进下去,我们就可以称 ...

  7. 【原创】一文彻底搞懂安卓WebView白名单校验

    前言 近两年公司端侧发现的漏洞很大一部分都出在WebView白名单上,针对这类漏洞安全编码团队也组织过多次培训,但是这种漏洞还是屡见不鲜.下面本人就结合产品中容易出现问题的地方,用实例的方式来总结一下 ...

  8. minio-对象存储

    1. 简介 官方地址 MinIO 是一个基于Apache License v2.0开源协议的对象存储服务.它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片.视频.日志文件. ...

  9. jQuery中的效果(九):hide()、show()、slideUp()、slideDown()、slideToggle()、fadeOut()、fadeIn()、fadeTo()、animate等

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  10. APP 兼容性测试之云测平台体验

    前言 兼容性测试主要通过人工或自动化的方式,在需要覆盖的终端设备上进行功能用例执行,查看软件性能.稳定性等是否正常. 对于需要覆盖的终端设备,大型互联网公司,像BAT,基本都有自己的测试实验室,拥有大 ...