Take jobs sorted by end time: (1,2,$30), (2,5,$80), (4,6,$20). Initialize dp[0] = 0.
Job : ends at , profit . No earlier jobs exist, so dp[1] = max(dp[0], 30 + 0) = 30.
Job : ends at , profit . Binary search for the latest job ending at or before start time . That's job (ends at ). So dp[2] = max(dp[1], 80 + dp[1]) = max(30, 80 + 30) = 110.
Job : ends at , profit . Latest job ending at or before time is job . So dp[3] = max(dp[2], 20 + dp[1]) = max(110, 20 + 30) = 110.
The answer is . Sorting takes . Each of the jobs needs one binary search at , so total time is . You store DP values, so space is .