deadwing97

SONGSHOP Author

Mar 25th, 2019
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int MAXN = 5010;
  6. const int MAXPRICE = 5010;
  7.  
  8. int n, m, totalPrice;
  9. vector<pair<long long, long long> > albums[MAXN];
  10.  
  11. long long dp[MAXN][MAXPRICE], albumPrice[MAXN], albumValue[MAXN];
  12.  
  13. int main() {
  14.     cin >> n >> m >> totalPrice;
  15.     for (int i = 0; i < n; i++) {
  16.         int x, y, val;
  17.         cin >> x >> y >> val;
  18.         albums[x].push_back({y, val});
  19.         albumValue[x] += val;
  20.     }
  21.     for (int i = 1; i <= m; i++)
  22.         cin >> albumPrice[i];
  23.     int idx = 0;
  24.     for (int i = 1; i <= m; i++) {
  25.         for (auto song: albums[i]) {
  26.             idx++;
  27.             for (int price = 0; price <= totalPrice; price++) {
  28.                 dp[idx][price] = max(dp[idx - 1][price], (price >= song.first) ? dp[idx - 1][price - song.first] + song.second : 0);
  29.             }
  30.         }
  31.         idx++;
  32.         for (int price = 0; price <= totalPrice; price++) {
  33.             dp[idx][price] = max(dp[idx - 1][price], (price >= albumPrice[i]) ? dp[idx - (int)albums[i].size() - 1][price - albumPrice[i]] + albumValue[i] : 0);
  34.         }
  35.     }
  36.     cout << dp[idx][totalPrice] << endl;
  37.     return 0;
  38. }
Add Comment
Please, Sign In to add comment