一:题目
二:上码
class Solution {
public:/**思路:求差,将结果放到一个容器当中,然后的话,排序,*/int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {vector<int> ans;int count = 0;for (int i = 0; i < capacity.size(); i++) {ans.push_back(capacity[i]-rocks[i]); }sort(ans.begin(),ans.end());for (int i = 0; i < ans.size(); i++) {if (ans[i] > 0 && additionalRocks >= ans[i]) {additionalRocks -= ans[i];ans[i] = 0;}}for (auto temp:ans) {if (temp == 0) count++;}return count;}
};