Delivery Billing with Rate History
HardSimulation ยท Rippling
Process ops, billing operations applied in order, and return one integer per ["total"].
["driver", id, rate]adds a driver paidratecents per hour.["rate", id, rate, effective]changes that driver's rate from minuteeffectiveonward. Of two changes with equaleffective, the later operation wins.["delivery", did, id, start, end]records a delivery ofend - startminutes, billed entirely at the rate in effect at minutestart. A repeateddidis ignored.["total"]returns the sum ofrate * minutes / 60cents over all recorded deliveries, using every rate change received so far, rounded half up to a whole cent once.
Example 1
- Input:
- ops = [["driver", "d1", 600], ["delivery", "a", "d1", 30, 120], ["total"], ["rate", "d1", 1200, 20], ["total"], ["delivery", "a", "d1", 200, 260], ["delivery", "b", "d1", 10, 20], ["total"]]
- Output:
- [900, 1800, 1900]
- Explanation
- The back-dated rate (effective at minute 20) also applies to delivery a, which started at 30. Delivery b starts before minute 20 and keeps rate 600.
Example 2
- Input:
- ops = [["driver", "x", 100], ["delivery", "p", "x", 0, 1], ["delivery", "q", "x", 5, 6], ["total"]]
- Output:
- [3]
Example 3
- Input:
- ops = [["driver", "x", 30], ["delivery", "p", "x", 0, 1], ["total"], ["delivery", "q", "x", 1, 2], ["total"]]
- Output:
- [1, 1]
- Explanation
- Half a cent rounds up to 1. After the second delivery the exact total is 1.
Constraints
1 <= ops.length <= 2000- Every
idused by arateordeliverywas added by an earlierdriveroperation, and each driver is added once 0 <= rate <= 1000000 <= effective, start < end <= 10^6