fork download
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. #define NAME "a"
  6. #define fas() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  7. #define Fin() if(NAME != ""){freopen(NAME".inp" , "r" , stdin);freopen(NAME".out" , "w" , stdout);}
  8. #define int long long
  9. #define endl "\n"
  10. #define INF LLONG_MAX
  11.  
  12. struct info{
  13. int w, v;
  14. };
  15.  
  16. void solve(){
  17. int n , m;
  18. cin >> n >> m;
  19. vector<info> a;
  20. int u , v , c;
  21. for(int i = 0 ; i < n ; i++){
  22. cin >> u >> v >> c;
  23. for(int j = 0 ; (1 << j) <= c; j++){
  24. int tmp = 1 << j;
  25. a.push_back({tmp * u , tmp * v});
  26. c -= tmp;
  27. }
  28. if(c > 0)
  29. a.push_back({c * u , c * v});
  30. }
  31.  
  32. vector<int> dp(m+1 , 0);
  33.  
  34. for(int i = 0 ; i < a.size() ; i++){
  35. for(int j = m ; j >= 0 ; j--)
  36. if(a[i].w <= j){
  37. dp[j] = max(dp[j - a[i].w] + a[i].v , dp[j]);
  38. }
  39. }
  40.  
  41. cout << *max_element(dp.begin() , dp.end()) << endl;
  42. }
  43.  
  44. signed main(){
  45. //Fin();
  46. fas();
  47. int t = 1;
  48. //cin >> t;
  49. while(t--){
  50. solve();
  51. }
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
0