Advertisement
Alex_tz307

TheProgrammingContestDivOne

Apr 5th, 2021 (edited)
1,535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using int64 = long long;
  5.  
  6. const int64 INF = 1e16L;
  7.  
  8. class TheProgrammingContestDivOne {
  9.   public:
  10.     class problem {
  11.       public:
  12.         int64 m, d, t;
  13.  
  14.         bool operator < (const problem &A) const {
  15.           return A.d * t <= d * A.t;
  16.         }
  17.     };
  18.  
  19.     int N, total_time;
  20.     vector<problem> a;
  21.     vector<vector<int64>> dp;
  22.  
  23.     void max_self(int64 &x, int64 y) {
  24.       x = max(x, y);
  25.     }
  26.  
  27.     int64 solve(int i, int t) {
  28.       if (i == N)
  29.         return 0LL;
  30.       if (dp[i][t] != -INF)
  31.         return dp[i][t];
  32.       int64 best = solve(i + 1, t), new_time = t + a[i].t;
  33.       if (new_time <= total_time) {
  34.         int64 reward = a[i].m - a[i].d * new_time;
  35.         if (reward >= 0) {
  36.           int64 ans = solve(i + 1, new_time) + reward;
  37.           max_self(best, ans);
  38.         }
  39.       }
  40.       return dp[i][t] = best;
  41.     }
  42.  
  43.     int find(int T, vector<int> maxPoints, vector<int> pointsPerMinute, vector<int> requiredTime) {
  44.       N = maxPoints.size();
  45.       total_time = T;
  46.       for (int i = 0; i < N; ++i)
  47.         a.push_back({maxPoints[i], pointsPerMinute[i], requiredTime[i]});
  48.       sort(a.begin(), a.end());
  49.       dp = vector<vector<int64>>(N, vector<int64>(total_time + 1, -INF));
  50.       return solve(0, 0);
  51.     }
  52. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement