【13.77%】【codeforces 734C】Anton and Making Potions
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
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.
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 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 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 (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.
【题目链接】:http://codeforces.com/contest/734/problem/C
【题解】
分两种情况;
1.只用第二种魔法;
2.用第一种魔法,第二种魔法不一定用;
第1种就二分下第二种魔法;找到最大的可以接受的di;因为di,ci都是单增的所以这个di对应的ci也即最优解;
第二种就先枚举第一种魔法用哪一种;然后用新的x和剩余的魔法值去尝试第二种魔法(当然也要二分);
那些不二分的人是怎么想的。
终测84%之后就变成龟速了…我想大概就是第三题不写二分的结果吧。时限4s误导了大家?:)
【完整代码】
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXMK = 2e5+10;
int n,m,k;
LL x,s;
LL a[MAXMK],d[MAXMK],b[MAXMK];
int c[MAXMK];
int getmax(LL rest)
{
int l = 1,r = k,ans = -1;
while (l <= r)
{
int m = (l+r)>>1;
if (d[m] <= rest)
ans = m,l = m+1;
else
r = m-1;
}
return ans;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> n >> m >> k;
cin >> x >> s;
for (int i = 1;i <= m;i++)
cin >> a[i];
for (int i = 1;i <= m;i++)
cin >> b[i];
for (int i = 1;i <= k;i++)
cin >> c[i];
for (int i = 1;i <= k;i++)
cin >> d[i];
LL ans1 = -1;
//只用第二种
int pos = getmax(s);
if (pos!=-1)
{
int rest = n-c[pos];
ans1 = rest*x;
}
//用第一种,再看第二种要用不用
LL ans2 = -1;
for (int i = 1;i <= m;i++)
{
LL tx = x,ts = s;
if (b[i] <= ts)
{
ts-=b[i];
tx=a[i];
int pos1 = getmax(ts);
if (pos1!=-1)
{
int rest = n-c[pos1];
if (ans2 == -1)
ans2 = rest*tx;
else
ans2 = min(ans2,rest*tx);
}
else
if (ans2 == -1)
ans2 = 1LL*n*tx;
else
ans2 = min(ans2,1LL*n*tx);
}
}
if (ans1 == -1 && ans2 ==-1)
cout << 1LL*n*x<<endl;
else
if (ans1 == -1 && ans2!=-1)
cout << ans2 << endl;
else
if (ans1 !=-1 && ans2 == -1)
cout << ans1 << endl;
else
cout << min(ans1,ans2)<<endl;
return 0;
}
【13.77%】【codeforces 734C】Anton and Making Potions的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【77.78%】【codeforces 625C】K-special Tables
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【77.39%】【codeforces 734A】Anton and Danik
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【13.91%】【codeforces 593D】Happy Tree Party
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 793D】Presents in Bankopolis
[题目链接]:http://codeforces.com/contest/793/problem/D [题意] 给你n个点, 这n个点 从左到右1..n依序排; 然后给你m条有向边; 然后让你从中选出 ...
- 【57.97%】【codeforces Round #380A】Interview with Oleg
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【42.86%】【Codeforces Round #380D】Sea Battle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【41.43%】【codeforces 560C】Gerald's Hexagon
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- 使用Maven构建eclipse项目 (以zorka为例)
第一步:下载和配置Maven 下载地址:http://maven.apache.org/download.cgi 下载第二项(binary zip)后解压,如图. 第二步:添加环境变量 MAVEN_H ...
- LeetCode Algorithm 06_ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- Altium Designer布局移动原件的问题
- Python 极简教程(二)编码工具
Python 的编码工具很多.目前最流行的是 pycharm,关于 pycharm 的安装使用请参考 PyCharm安装使用教程. 而学习过程中,我觉得最好用的,还是 Python 自带的练习工具 I ...
- 【Codeforces Round #299 (Div. 2) E】Tavas and Pashmaks
[链接] 我是链接,点我呀:) [题意] 游泳+跑步比赛. 先游泳,然后跑步. 最先到终点的人是winner. 但是现在游泳的距离和跑步的距离长度都不确定. S和R. 给你n个人,告诉你每个人游泳的速 ...
- Linux 内核源代码分析 chap 2 存储管理 (5)
物理页面分配 linux 内核 2.4 中有 2 个版本号的物理页面分配函数 alloc_pages(). 一个在 mm/numa.c 中, 还有一个在 mm/page_alloc.c 中, 依据条件 ...
- 使用Samba在Linux服务器上搭建共享文件服务
最近我们的小团队需要在服务器上共分出一个共享文件夹用于大家存放公共的资源文档, 大家想啊,这肯定很简单呀,在Windows下面只要创建相关的windows account,共享某个文件夹,把读/写权限 ...
- screenX, clientX, pageX
screenX:鼠标相对屏幕左上角的水平偏移量. clientX:鼠标相对于浏览器左上角的水平偏移量,会随着滚动条的移动而移动. pageX:鼠标相对浏览器左上角的水平偏移量.不会随着滚动条的移动而移 ...
- crontab经验 分类: B3_LINUX 2015-03-06 11:17 282人阅读 评论(0) 收藏
1.基本格式 第1列分钟1-59 第2列小时1-23(0表示子夜) 第3列日1-31 第4列月1-12 第5列星期0-6(0表示星期天) 第6列要运行的命令 2.关于日志 (1)基本日志位 ...
- Python 奇葩语法
a = 1, 2, 3 赋值后的结果,a == (1, 2, 3),将一个元组(tuple)赋给了变量 a (1, 2) + (3, ) ⇒ (1, 2, 3),并不能说明 tuple 可以添加新的元 ...