from typing import List


class Solution:
    def numRescueBoats(self, people: List[int], limit: int) -> int:
        res = 0
        people.sort()

        l, r = 0, len(people) - 1

        while l < r:
            res += 1
            if people[r] + people[l] <= limit:
                l += 1
            r -= 1

        if l == r:
            res += 1
        return res

from typing import List


class Solution:
    def numRescueBoats(self, people: List[int], limit: int) -> int:
        res = 0
        people.sort()

        l, r = 0, len(people) - 1

        while l < r:
            res += 1
            if people[r] + people[l] <= limit:
                l += 1
            r -= 1

        if l == r:
            res += 1
        return res
