Maximum Taxi Earnings
Problem statement
You are given three arrays pickup, drop, and tip describing taxi ride requests. Ride i starts at pickup[i], ends at drop[i], and earns (drop[i] - pickup[i]) + tip[i].
You can complete only one ride at a time. After finishing a ride at position x, you may take another ride whose pickup position is at least x.
Return the maximum total earnings obtainable from a subset of non-overlapping rides.
Function
maxTaxiEarnings(pickup: long[], drop: long[], tip: long[]) → longExamples
Example 1
pickup = [2,4,5]drop = [5,5,7]tip = [4,1,2]return = 11Take the ride from 2 to 5 for 7, then the ride from 5 to 7 for 4.
Example 2
pickup = [1,2,3]drop = [2,3,4]tip = [0,0,0]return = 3All three rides are compatible and each earns 1.
Example 3
pickup = [0]drop = [1000000000000]tip = [100000]return = 1000000100000The only ride earns its distance plus its tip. This example also shows why 64-bit arithmetic is required.
Constraints
1 <= pickup.length = drop.length = tip.length <= 10^4.0 <= pickup[i] < drop[i] <= 10^12.0 <= tip[i] <= 10^5.