> For the complete documentation index, see [llms.txt](https://851958789.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://851958789.gitbook.io/notes/0881_boats_to_save_people/slt.md).

# Solution1 双指针 + 贪心

* 时间复杂度 $O(n \* logn)$
* 空间复杂度 $O(1)$

要使需要的船数尽可能地少，应当使载两人的船尽可能地多。 考虑体重最轻的人

* 若他不能与体重最重的人同乘一艘船，那么体重最重的人无法与任何人同乘一艘船，此时应单独分配一艘船给体重最重的人
* 若他能与体重最重的人同乘一艘船，那么他能与其余任何人同乘一艘船，为了尽可能地利用船的承载重量，选择与体重最重的人同乘一艘船是最优的

所以，我们要尽可能的把最重和最轻的人放在一起。

先小到大排序。

从右往左遍历重的人，如果同时带上左边轻的人，则 l++
