← 返回 doordash 的题目列表Dasher Naive Pay (Active-time pay with overlapping orders)
类型:online_judge
Dasher Naive Pay (Active-time pay)
You are a downstream service. Given an event list from upstream, compute a Dasher’s total base pay.
Pay rules
Base rate: 0.3 USD per minute.
For each order orderId:
The order becomes active starting at the ACCEPT event time (inclusive).
The order stops being active starting at the FULFILL event time (inclusive).
Multiplicity: if there are k active orders during a time span, the pay rate for that span is:
k * 0.3 USD/min
Sum pay over all time spans and return the total, rounded to 2 decimals.
Input
An event list events, each event has:
time: integer timestamp in minutes.
orderId: unique order id (string).
action: only ACCEPT or FULFILL.
The list may be unsorted. If multiple events share the same time, process ACCEPT before FULFILL.
Output
Return the total pay as a floating number rounded to 2 decimals.
Example
Events:
(375, "A", ACCEPT) // 06:15
(378, "B", ACCEPT) // 06:18
(396, "A", FULFILL) // 06:36
(405, "B", FULFILL) // 06:45
Output: 14.40
Constraints
1 <= len(events) <= 2 * 10^5
0 <= time <= 10^9
orderId is a non-empty string
Task
Implement calculateNaivePay(events) -> double.
Example
Input
4
375 A ACCEPT
378 B ACCEPT
396 A FULFILL
405 B FULFILL
Output
14.40