codeforces_734C_二分
2016-11-19 23:20
337 查看
C.AntonandMakingPotions
timelimitpertest
4seconds
memorylimitpertest
256megabytes
input
standardinput
output
standardoutput
Antonisplayingaveryinterestingcomputergame,butnowheisstuckatoneofthelevels.Topasstothenextlevelhehastopreparenpotions.
Antonhasaspecialkettle,thatcanprepareonepotionsinxseconds.Also,heknowsspellsoftwotypesthatcanfastertheprocessofpreparingpotions.
Spellsofthistypespeedupthepreparationtimeofonepotion.Therearemspellsofthistype,thei-thofthemcostsbimanapointsandchangesthepreparationtimeofeachpotiontoaiinsteadofx.
Spellsofthistypeimmediatelypreparesomenumberofpotions.Thereareksuchspells,thei-thofthemcostsdimanapointsandinstantlycreatecipotions.
Antoncanusenomorethanonespellofthefirsttypeandnomorethanonespellofthesecondtype,andthetotalnumberofmanapointsspentshouldnotexceeds.ConsiderthatallspellsareusedinstantlyandrightbeforeAntonstartstopreparepotions.
Antonwantstogettothenextlevelasfastaspossible,soheisinterestedintheminimumnumberoftimeheneedstospentinordertoprepareatleastnpotions.
Input
Thefirstlineoftheinputcontainsthreeintegersn,m,k(1 ≤ n ≤ 2·10^9, 1 ≤ m, k ≤ 2·10^5)—thenumberofpotions,Antonhastomake,thenumberofspellsofthefirsttypeandthenumberofspellsofthesecondtype.
Thesecondlineoftheinputcontainstwointegersxands(2 ≤ x ≤ 2·10^9, 1 ≤ s ≤ 2·10^9)—theinitialnumberofsecondsrequiredtoprepareonepotionandthenumberofmanapointsAntoncanuse.
Thethirdlinecontainsmintegersai(1 ≤ ai < x)—thenumberofsecondsitwilltaketoprepareonepotionifthei-thspellofthefirsttypeisused.
Thefourthlinecontainsmintegersbi(1 ≤ bi ≤ 2·10^9)—thenumberofmanapointstousethei-thspellofthefirsttype.
Therearekintegersci(1 ≤ ci ≤ n)inthefifthline—thenumberofpotionsthatwillbeimmediatelycreatedifthei-thspellofthesecondtypeisused.It'sguaranteedthatciarenotdecreasing,i.e.ci ≤ cjifi < j.
Thesixthlinecontainskintegersdi(1 ≤ di ≤ 2·10^9)—thenumberofmanapointsrequiredtousethei-thspellofthesecondtype.It'sguaranteedthatdiarenotdecreasing,i.e.di ≤ djifi < j.
Output
Printoneinteger—theminimumtimeonehastospentinordertopreparenpotions.
Examples
input
output
input
output
timelimitpertest
4seconds
memorylimitpertest
256megabytes
input
standardinput
output
standardoutput
Antonisplayingaveryinterestingcomputergame,butnowheisstuckatoneofthelevels.Topasstothenextlevelhehastopreparenpotions.
Antonhasaspecialkettle,thatcanprepareonepotionsinxseconds.Also,heknowsspellsoftwotypesthatcanfastertheprocessofpreparingpotions.
Spellsofthistypespeedupthepreparationtimeofonepotion.Therearemspellsofthistype,thei-thofthemcostsbimanapointsandchangesthepreparationtimeofeachpotiontoaiinsteadofx.
Spellsofthistypeimmediatelypreparesomenumberofpotions.Thereareksuchspells,thei-thofthemcostsdimanapointsandinstantlycreatecipotions.
Antoncanusenomorethanonespellofthefirsttypeandnomorethanonespellofthesecondtype,andthetotalnumberofmanapointsspentshouldnotexceeds.ConsiderthatallspellsareusedinstantlyandrightbeforeAntonstartstopreparepotions.
Antonwantstogettothenextlevelasfastaspossible,soheisinterestedintheminimumnumberoftimeheneedstospentinordertoprepareatleastnpotions.
Input
Thefirstlineoftheinputcontainsthreeintegersn,m,k(1 ≤ n ≤ 2·10^9, 1 ≤ m, k ≤ 2·10^5)—thenumberofpotions,Antonhastomake,thenumberofspellsofthefirsttypeandthenumberofspellsofthesecondtype.
Thesecondlineoftheinputcontainstwointegersxands(2 ≤ x ≤ 2·10^9, 1 ≤ s ≤ 2·10^9)—theinitialnumberofsecondsrequiredtoprepareonepotionandthenumberofmanapointsAntoncanuse.
Thethirdlinecontainsmintegersai(1 ≤ ai < x)—thenumberofsecondsitwilltaketoprepareonepotionifthei-thspellofthefirsttypeisused.
Thefourthlinecontainsmintegersbi(1 ≤ bi ≤ 2·10^9)—thenumberofmanapointstousethei-thspellofthefirsttype.
Therearekintegersci(1 ≤ ci ≤ n)inthefifthline—thenumberofpotionsthatwillbeimmediatelycreatedifthei-thspellofthesecondtypeisused.It'sguaranteedthatciarenotdecreasing,i.e.ci ≤ cjifi < j.
Thesixthlinecontainskintegersdi(1 ≤ di ≤ 2·10^9)—thenumberofmanapointsrequiredtousethei-thspellofthesecondtype.It'sguaranteedthatdiarenotdecreasing,i.e.di ≤ djifi < j.
Output
Printoneinteger—theminimumtimeonehastospentinordertopreparenpotions.
Examples
input
2032 1099 243 201040 415 1080
output
20
input
2032 1099 243 200100400 415 100800
output
200 题意:要制造n个物品,制造一个需要x分钟,一共s的技能点,有两种技能,第一种使制造每一个的时间变为指定值, 第二种瞬间制造指定个数物品,两种技能消耗指定的技能点,每种技能只能用一次。问最短多久能完成任务。 思路:最短时间为:t*(n-w)。找到它的最小值,枚举第一种技能求出t,因为第二种技能是有序的, 可以二分查找剩余技能点能使用的w最大的技能。 注意:有可能不用第一种技能,只用第二种技能。
#include<iostream> #include<cstdio> #include<cstring> usingnamespacestd; #defineN200005 #defineLLlonglong #defineINF(4*1e18+5) structOne { intcost,time; }one ; structTwo { intcost,num; }two ; intk; intFind(intx) { intl=0,r=k-1,res=0; while(l<=r) { intmid=(l+r)>>1; if(two[mid].cost>x) r=mid-1; else { l=mid+1; res=two[mid].num; } } returnres; } intmain() { intn,m,x,s; scanf("%d%d%d%d%d",&n,&m,&k,&x,&s); for(inti=0;i<m;i++) scanf("%d",&one[i].time); for(inti=0;i<m;i++) scanf("%d",&one[i].cost); for(inti=0;i<k;i++) scanf("%d",&two[i].num); for(inti=0;i<k;i++) scanf("%d",&two[i].cost); LLres=x*(LL)(n-Find(s));//这里特别注意,做的时候这里出错,只用第二种技能或者都不用 LLtime=x,mana=s; for(inti=0;i<m;i++) { time=x,mana=s; if(one[i].cost<=s) { time=one[i].time; mana=s-one[i].cost; } intred=Find(mana); //cout<<mana<<""<<red<<endl; res=min((LL)time*(n-red),res); } printf("%I64d\n",res); return0; }
相关文章推荐
- codeforces - 734C - Anton and Making Potions(二分)
- Codeforces-734C-Anton and Making Potions(枚举+二分)
- CodeForces - 734C Anton and Making Potions (二分)
- codeforces 191 E (树状数组+二分)
- 【CodeForces 729C】【二分+贪心】Road to Cinema 题解
- CodeForces 626E Simple Skewness(二分)
- codeforces 895/B sort+二分
- Codeforces 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案
- CodeForces 251 A.Points on Line(二分)
- codeforces_679B. Bear and Tower of Cubes(贪心+二分+dfs)
- Codeforces 854D Jury Meeting【思维+前后缀和+二分】
- 二分 Tavas and Karafs:CodeForces 535C
- codeforces 817C Really Big Numbers 二分
- Codeforces 483B - Friends and Presents(二分)
- Codeforces 348A - Mafia (二分答案)
- codeforces 779D 二分
- CodeForces540E【树状数组+二分】
- CodeForces - 801C Voltage Keepsake(二分)
- Codeforces 609D Gadgets for dollars and pounds【二分+贪心】
- Codeforces 513F2 题解 (网络流-最大流 二分 BFS)