Freelance Contracts
You are a freelancer who has received N contract offers. Each contract i has a specific start day si, end day ei, and a payment amount pi. You can only work on one contract at a time, meaning if you accept a contract ending on day X, the next contract you accept must start on day X+1 or later.
Your task is to find the maximum total payment you can earn by choosing an optimal non-overlapping subset of the contracts.
Example 1:
Input: n = 3 , contracts = [[2,4,4], [3,6,6], [6,8,2]]
Output: 6
Explanation:
Options:
Take [2,4,4] + [6,8,2] ā 6 Take [3,6,6] ā 6 Answer = 6
Example 2:
Input: n = 4, contracts = [[1,3,5], [2,5,6], [4,6,5], [6,7,4]]
Output: 10
Explanation: Valid combinations:
[1,3,5] + [4,6,5] = 10 [2,5,6] + [6,7,4] = 10 Answer = 10
Now Your Turn!
Pick the correct output for the given inputInput: n = 2 , contracts = [[1,10,100], [2,3,50]]
Still unsure what the problem is asking ?
Letās go through a few more examples, step by step, to make it clearer.
Constraints:
1 ⤠n ⤠2 * 105
1 ⤠si ⤠ei ⤠109
1 ⤠pi ⤠109