← 返回 doordash 的题目列表Dasher Pay: Calculate Active-Time Payment
类型:online_judge
Problem: Dasher Pay
A DoorDash Dasher is paid based on their active delivery time. You are given a list of delivery events for one Dasher. Each delivery has one START event and one END event.
The Dasher is considered active whenever they have at least one unfinished delivery. If the Dasher is handling multiple deliveries at the same time, the overlapping time should only be paid once.
Calculate the Dasher's total pay in cents.
Input Format
n rate
id_1 timestamp_1 event_1
id_2 timestamp_2 event_2
...
id_n timestamp_n event_n
n: the number of events.
rate: pay rate in cents per minute.
id_i: delivery ID, with no spaces.
timestamp_i: event timestamp in integer minutes.
event_i: either START or END.
Output Format
Print one integer: the total pay in cents.
Constraints
0 <= n <= 2 * 10^5
n is even.
0 <= timestamp_i <= 10^9
Each delivery ID has exactly one START and one END, and its START timestamp is smaller than its END timestamp.
Events may be given out of order.
Overlapping active delivery time should be counted only once.
Example
Input:
4 200
A 0 START
B 5 START
A 10 END
B 15 END
Output:
3000
Explanation:
Delivery A is active during [0, 10], and delivery B is active during [5, 15]. The Dasher's total active time is [0, 15], which is 15 minutes. The total pay is 15 * 200 = 3000 cents.
Example
Input
4 100
A 0 START
A 10 END
B 15 START
B 20 END
Output
1500