[二分] Codefoces Anton and Making Potions

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 210 992 4 320 10 404 1510 80

output

Copy

20

input

Copy

20 3 210 992 4 3200 100 4004 15100 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),注意要单独算出两种魔法都不用,只用第一种魔法和只用第二种魔法的情况,这是本题的坑点

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

原文地址:https://www.cnblogs.com/Railgun000/p/11376313.html

时间: 2024-08-29 23:21:49

[二分] Codefoces Anton and Making Potions的相关文章

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

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 typ

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

题目链接:http://codeforces.com/problemset/problem/734/C 题目大意:要制作n个药,初始制作一个药的时间为x,魔力值为s,有两类咒语,第一类周瑜有m种,每种咒语使制作一个药的时间变成a[i],花费b[i]的魔力,第二类咒语有k种,每种咒语瞬间产生c[i]个药,花费d[i]的魔力,c[i]和d[i]都是不递减的,求最短时间内产生n个药的时间.解题思路:因为c[i]和d[i]都是不降的,所以可以枚举a[i],然后二分查找花费小于t-b[i]的第二类咒语.注

Codeforces Round #379 (Div. 2) 总结分享

前言 初入acm的新手,打算在cf混.这几天没有比赛,就做了个最新的Virtual participation.虽然说div2比较简单,但还是被虐得体无完肤...Orz.两个小时,共6道题.最后只AC了AB两道,花了20分钟,剩下的100分钟也不知道哪去了(逃 A.B两道水题没什么说的.那我们从C题开始吧: C. Anton and Making Potions 题意: 制作n瓶药水,初始时每制作一瓶花费x秒,有两类法术,第一类(包含m个法术)使制作每瓶药的时间由x变为a[i] (a[i] <

codeforces_734C

Anton and Making Potions 安东和他的药水 安东做一份药水有2种方法: 1.把做药水的时间X换成Ai,花费Bi 魔法 2.一瞬间做成Ci份药水,花费Di 魔法 问,最少需要多少时间 二分魔法值 n,m,k = list(map(int,input().split())) x,s = list(map(int,input().split())) a_time = list(map(int,input().split())) a_cost = list(map(int,inpu

Codeforces Round #379 (Div. 2) Analyses By Team:Red &amp; Black

A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lucky_ji: 水题,模拟统计A和D的数目比较大小输出结果即可 Tags: Implementation B.Anton and Digits Problems: 给定k2个2,k3个3,k5个5及k6个6,可以组成若干个32或256,求所有方案中Sigma的最大值 Analysis: lucky_ji: 同

Codeforces Round #404 (Div. 2) C 二分,水 D 数学,好题 E 分块

Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale 题意:仓库容量n,每天运来m粮食,第 i 天被吃 i 粮食,问第几天仓库第一次空掉. tags:==SB题 注:二分边界判断,数据范围爆long long判断. // CF404 C #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000&

送礼物(二分答案+单调队列)

QUESTION: JYY和CX的结婚纪念日即将到来,JYY来到萌萌开的礼品店选购纪念礼物.萌萌的礼品店很神奇,所有出售的礼物都按照特定的顺序都排成一列,而且相邻的礼物之间有一种神秘的美感.于是,JYY决定从中挑选连续的一些礼物,但究竟选 哪些呢?假设礼品店一共有\(N\)件礼物排成一列,每件礼物都有它的美观度.排在第\(i\)(\(1\leq i \leq N\))个位置的礼物美观度为正整数\(A_i\).JYY决定选出其中连续的一段,即编号为礼物\(i\),\(i+1\),....,\(j-

2.1 二分分类

本周学习神经网络编程的基础知识 构建神经网络,有些技巧是非常重要 神经网络的计算过程中,通常有一个正向的过程(正向传播步骤),接着会有一个反向步骤(反向传播步骤), 为什么神经网络的计算可以分为前向传播和反向传播两个分开的过程?本周课程通过使用logistic回归来阐述,以便于能够更好的理解, logistic回归是一个用于二分分类的算法 比如有一个二分分类问题的例子, 假如有一张图像作为输入是这样的,你想输出识别此图的标签,如果是猫,输出1,如果不是,则输出0 使用y来表示输出的结果标签, 来

HDU3715(二分+2-SAT)

Go Deeper Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3184    Accepted Submission(s): 1035 Problem Description Here is a procedure's pseudocode: go(int dep, int n, int m)beginoutput the valu