mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
routine
This commit is contained in:
20
25/12/3074.cpp
Normal file
20
25/12/3074.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#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;;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user