标签:vector amp col zoj cstring head div bzoj using
1 #include <map> 2 #include <cmath> 3 #include <vector> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <iostream> 8 #include <algorithm> 9 # define maxn 300 10 using namespace std; 11 typedef long long LL; 12 LL m,F; 13 int n; 14 struct Food{ 15 LL tim,p; 16 }g[maxn]; 17 bool cmp(const Food a,const Food b){ 18 if(a.tim==b.tim) return a.p>b.p; 19 return a.tim<b.tim; 20 } 21 Food q[maxn]; 22 int head,tail; 23 void init(){ 24 scanf("%lld%lld%d",&m,&F,&n); 25 for(int i=1;i<=n;i++) scanf("%lld%lld",&g[i].p,&g[i].tim); 26 sort(g+1,g+n+1,cmp); 27 head=tail=1; 28 for(int i=1;i<=n;i++){ 29 while(head<tail && g[i].p<q[tail-1].p) tail--; 30 q[tail++]=g[i]; 31 } 32 for(int i=1;i<tail;i++) g[i]=q[i]; 33 n=tail-1; 34 } 35 LL check(LL x){ 36 LL rm=m-F*x, mt=0, ret=0; 37 LL tmp; 38 for(int i=1;i<=n;i++){ 39 if(mt<=g[i].tim){ 40 tmp=g[i].tim-mt+1; 41 tmp=min(tmp,rm/(g[i].p*x)); 42 ret+=tmp*x; 43 rm-=g[i].p*tmp*x; 44 mt+=tmp; 45 } 46 if(mt<=g[i].tim){ 47 tmp=min(x,rm/g[i].p); 48 ret+=tmp; 49 rm-=tmp*g[i].p; 50 mt++; 51 } 52 } 53 return ret; 54 } 55 void work(){ 56 LL l=1,r=m/(g[1].p+F),mid1,mid2,ans=0,v1,v2; 57 while(l<=r){ 58 mid1=l+(r-l)/3,mid2=r-(r-l)/3; 59 v1=check(mid1); v2=check(mid2); 60 if(v1<v2) ans=max(ans,v2),l=mid1+1; 61 else if(v1>v2) ans=max(ans,v1),r=mid2-1; 62 else ans=max(ans,v1),l=mid1+1,r=mid2-1; 63 } 64 cout<<ans<<endl; 65 } 66 int main(){ 67 // freopen("a.in","r",stdin); 68 init(); 69 work(); 70 }
标签:vector amp col zoj cstring head div bzoj using
原文地址:http://www.cnblogs.com/FOXYY/p/7616233.html