您的位置:首页 > 其它

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
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;
}





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: