leetcode

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

2279.cpp (490B)


      1 class Solution {
      2   public:
      3     int maximumBags(vector<int> &capacity, vector<int> &rocks, int additionalRocks) {
      4         for (int i = 0; i < capacity.size(); i++)
      5             rocks[i] = capacity[i] - rocks[i];
      6         sort(rocks.begin(), rocks.end());
      7 
      8         int res = 0;
      9         for (int i = 0; i < capacity.size(); i++)
     10             if (rocks[i] <= additionalRocks)
     11                 additionalRocks -= rocks[i], res++;
     12             else
     13                 break;
     14         return res;
     15     }
     16 };