Untitled
unknown
python
a year ago
804 B
4
Indexable
Never
class Solution: def maximizeTheProfit(self, n: int, offers: List[List[int]]) -> int: offers = sorted(offers, key=lambda x: x[0]) @cache def helper(index): curr_start, curr_end, curr_gold = offers[index] max_gold = -math.inf for i in range(index+1, len(offers)): next_start, _, _ = offers[i] if next_start > curr_end: max_gold = max(max_gold, helper(i)) if max_gold != -math.inf: return curr_gold + max_gold return curr_gold max_gold = -math.inf for i in range(len(offers)): max_gold = max(max_gold, helper(i)) return max_gold