A Knapsack problem

This is a biweekly contest problem from leetcode. We can solve it by using the idea from the knapsack problem.

In the knapsack problem, we can either take or not take.
For this one, we have 3 actions:
1a) Take the current interval and combine with the previous one
1b) Take the current interval and not combine with the previous one
2. Not take the current interval.

Hope it helps.