mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
20 lines
503 B
C++
20 lines
503 B
C++
#include <algorithm>
|
|
#include <numeric>
|
|
#include <vector>
|
|
|
|
class Solution {
|
|
public:
|
|
int minimumBoxes(std::vector<int>& apple, std::vector<int>& capacity) {
|
|
int sum = std::accumulate(apple.begin(),apple.end(),0);
|
|
std::sort(capacity.begin(),capacity.end(),[](int a,int b){return a>b;});
|
|
int ans = 0;
|
|
for(auto c : capacity){
|
|
sum -= c;
|
|
ans++;
|
|
if (sum <= 0) {
|
|
break;
|
|
}
|
|
}
|
|
return ans;;
|
|
}
|
|
}; |