3
static bool myfunction(vector<int> &a, vector<int> &b) {6
int maximumUnits(vector<vector<int>> &boxTypes, int truckSize) {7
// custom sort (in increasing order of numberOfUnitsPerBox as we have to8
// return maximum total number of units )9
sort(boxTypes.begin(), boxTypes.end(), myfunction);10
// greedily pick boxes till capacity is full12
for (auto box : boxTypes) {13
int x = min(box[0], truckSize); // choose minimum boxes from available14
// boxes and capacity left15
ans += (x * box[1]); // adding units in ans16
truckSize -= x; // reduce the capacity17
if (!truckSize) break; // capacity full