1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <ctype.h> #include <algorithm> #include <map> #include <vector> using namespace std; #define re register int #define maxn 1000000 const int N=1e4+5; const int T=1005; int n,hs,ms,he,me,tot; int t[N],c[N],p[N]; int dp[T]; int t1[maxn],c1[maxn]; int tp; inline void seg(){ for(re i=1;i<=n;++i){ int tmp=1; while(p[i]>=tmp){ p[i]-=tmp; t1[++tp]=tmp*t[i],c1[tp]=tmp*c[i]; tmp<<=1; } if(p[i]) t1[++tp]=p[i]*t[i],c1[tp]=p[i]*c[i]; } } int main(){ scanf("%d:%d %d:%d %d",&hs,&ms,&he,&me,&n); int tot=(he*60+me)-(hs*60+ms); for(re i=1;i<=n;++i){ scanf("%d%d%d",&t[i],&c[i],&p[i]); if(!p[i]) p[i]=T; } seg(); for(re i=1;i<=tp;++i) for(re j=tot;j>=t1[i];--j) dp[j]=max(dp[j],dp[j-t1[i]]+c1[i]); printf("%d\n",dp[tot]); return 0; }
|