← 返回 doordash 的题目列表Calculate Dasher Pay With Cancellations and Double-Pay Windows
类型:online_judge
Problem: Calculate Dasher Pay (Cancellations + Double-Pay Windows)
Given a list of delivery order records for a Dasher and a list of double-pay time windows, compute the Dasher’s total payout.
Pay Rules
Completed orders:
Pay is time-based: pay = duration * rate.
duration = end_time - start_time.
Canceled orders:
No time-based pay; the Dasher receives a fixed cancel_compensation.
Double-pay windows:
Any delivery time that overlaps a double-pay window is paid at 2x the normal rate.
If a completed delivery overlaps multiple windows, all overlapping portions are paid at 2x (equivalently, split the timeline and apply 2 * rate inside windows and 1 * rate outside).
Input
orders: list of order records, each containing at least:
start_time, end_time (end_time applies to completed orders)
rate
status: "completed" or "canceled"
double_pay_windows: list of windows, each with window_start, window_end
cancel_compensation: fixed payout for a canceled order.
Output
Return/print the Dasher’s total pay.
Requirements
Handle:
partial overlaps between deliveries and windows
overlap with multiple windows
windows that overlap/are adjacent (must still compute correctly)
canceled orders are paid only cancel_compensation and do not participate in double-pay calculations
Example Test Cases (illustrative)
orders=[(0,10,rate=2,completed)], windows=[] => 20
orders=[(0,10,rate=2,completed)], windows=[(5,8)] => 26
orders=[(10,20,rate=3,completed)], windows=[(0,100)] => 60
orders=[(0,10,rate=2,canceled)], windows=[(0,100)], cancel=5 => 5
windows overlap: orders=[(0,10,rate=1,completed)], windows=[(2,6),(4,8)] => 16
Example
Input
orders=[(0,10,2,completed)]
windows=[]
cancel=5
Output
20