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; } };
|