LeetCode-32

第 388 场周赛

100233. 重新分装苹果

  • 贪心
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
int minimumBoxes(vector<int>& apple, vector<int>& capacity) {
int need = accumulate(apple.begin(), apple.end(), 0);
sort(capacity.begin(), capacity.end());
int ans = 0, total = 0;
for(int i = capacity.size() - 1; i >= 0; i--) {
if(total < need) {
total += capacity[i];
ans++;
} else {
break;
}
}
return ans;
}
};

100247. 幸福值最大化的选择方案

  • 贪心
阅读更多