C++ 4 lines greedy O(n log n)
Disclaimer: this problem is probably inappropriate in the U.S. We will use as many boats as necessary to avoid any weight discrimination.\n\nWe always put the n
Disclaimer: this problem is probably inappropriate in the U.S. We will use as many boats as necessary to avoid any weight discrimination.\n\nWe always put the next heaviest person on the boat, plus the lightest person if combined weight is within the limit. \n```\nint numRescueBoats(vector<int>& ppl, int limit, int boats = 0) {\n  sort(begin(ppl), end(ppl));\n  for (int i = 0, j = ppl.size() - 1; i <= j; ++boats, --j) {\n    if (ppl[i] + ppl[j] <= limit) ++i;\n  }\n  return boats;\n}\n```
[]