leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0826.cpp (652B)


      1 class Solution {
      2   public:
      3     int maxProfitAssignment(const vector<int> &difficulty, const vector<int> &profit,
      4                             const vector<int> &worker) const {
      5         static int profits[100001];
      6         const int n = size(profit);
      7         int res = 0;
      8 
      9         memset(profits, 0x00, sizeof(profits));
     10         for (int i = 0; i < n; i++) {
     11             profits[difficulty[i]] = max(profits[difficulty[i]], profit[i]);
     12         }
     13 
     14         for (int i = 1; i < 100001; i++) {
     15             profits[i] = max(profits[i], profits[i - 1]);
     16         }
     17 
     18         for (const int m : worker)
     19             res += profits[m];
     20 
     21         return res;
     22     }
     23 };