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 47 48 49 50 51 52 53 54 55
| #include<iostream> #include<algorithm> #include<string> #include<cstring> #include<map> #include<vector> #include<set> #include<queue> #include<stack> #include<cmath> #include<string> using namespace std; typedef long long ll; constexpr int N = 10100; int c[N],dp[N],t[N]; void solve(){ int th1,ts1,th2,ts2,n; char cc; cin>>th1>>cc>>ts1>>th2>>cc>>ts2>>n; int tz = 60*(th2-th1)+ts2-ts1; for(int i = 1;i<=n;i++){ int t0,c0,s; cin>>t0>>c0>>s; if(s==0){ for(int j = 0;j<=tz;j++) if(j>=t0) dp[j] = max(dp[j],dp[j-t0]+c0); } else{ int cnt = 0; int k = 1; while(k<=s){ cnt++; t[cnt] = k*t0; c[cnt] = k*c0; s-=k; k*=2; } if(s){ cnt++; t[cnt] = s*t0; c[cnt] = s*c0; } for(int m = 1;m<=cnt;m++){ for(int j = tz;j>=0;j--){ if(j>=t[m]) dp[j] = max(dp[j],dp[j-t[m]]+c[m]); } } } } cout<<dp[tz]; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); solve(); }
|