The analytics team uses the live dashboard reporting function you built to view the total amount owed to all drivers. Implement the following functions:
-
void payUpTo(int payTime)Marks all deliveries ending at or beforepayTimeas paid. -
double getTotalCostUnpaid()Returns the total cost of all unpaid deliveries.
Constraints:
- Each delivery is paid at most once.
Example
Input: ["DeliveryCost", "addDriver", "addDriver", "getTotalCost", "getTotalCostUnpaid", "recordDelivery", "getTotalCost", "getTotalCostUnpaid", "recordDelivery", "getTotalCost", "getTotalCostUnpaid", "payUpTo", "getTotalCostUnpaid", "payUpTo", "getTotalCostUnpaid"] [[], [1, 20.0], [2, 30.0], [], [], [1, 1000000000, 1000003600], [], [], [2, 1000005000, 1000006800], [], [], [1000003600], [], [1000006800], []]
Output: [null, null, null, 0.0, 0.0, null, 20.0, 20.0, null, 35.0, 35.0, null, 15.0, null, 0.0]
Explanation:
DeliveryCost dc = new DeliveryCost();dc.addDriver(1, 20.0);dc.addDriver(2, 30.0);dc.getTotalCost();// Returns 0.0, no deliveries yet.dc.getTotalCostUnpaid();// Returns 0.0, nothing owed.dc.recordDelivery(1, 1000000000, 1000003600);// Logs a 1-hour delivery for driver 1 ($20.0).dc.getTotalCost();// Returns 20.0.dc.getTotalCostUnpaid();// Returns 20.0.dc.recordDelivery(2, 1000005000, 1000006800);// Logs a 0.5-hour delivery for driver 2 ($15.0).dc.getTotalCost();// Returns 35.0.dc.getTotalCostUnpaid();// Returns 35.0.dc.payUpTo(1000003600);// Marks all deliveries ending at or before the given time as paid.dc.getTotalCostUnpaid();// Returns 15.0, only driver 2's delivery remains unpaid.dc.payUpTo(1000006800);dc.getTotalCostUnpaid();// Returns 0.0, all deliveries paid.
