class Solution(object):

    def carPooling(self, trips, capacity):
        dcap = [0] * 1001
        for p, start, end in trips:
            dcap[start] -= p
            dcap[end] += p
        for delta in dcap:
            capacity += delta
            if capacity < 0:
                return False
        return True


trips = [[2, 1, 5], [3, 3, 7]]
capacity = 4
res = Solution().carPooling(trips, capacity)
print(res)

7904cca05b354fb53a27c29e5826e35c653c41ba
class Solution(object):
    <mask token>


<mask token>

class Solution(object):

    def carPooling(self, trips, capacity):
        dcap = [0] * 1001
        for p, start, end in trips:
            dcap[start] -= p
            dcap[end] += p
        for delta in dcap:
            capacity += delta
            if capacity < 0:
                return False
        return True


<mask token>

class Solution(object):

    def carPooling(self, trips, capacity):
        dcap = [0] * 1001
        for p, start, end in trips:
            dcap[start] -= p
            dcap[end] += p
        for delta in dcap:
            capacity += delta
            if capacity < 0:
                return False
        return True


<mask token>
print(res)

class Solution(object):

    def carPooling(self, trips, capacity):
        dcap = [0] * 1001
        for p, start, end in trips:
            dcap[start] -= p
            dcap[end] += p
        for delta in dcap:
            capacity += delta
            if capacity < 0:
                return False
        return True


trips = [[2, 1, 5], [3, 3, 7]]
capacity = 4
res = Solution().carPooling(trips, capacity)
print(res)
