Average Waiting Time
There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]:
arrivaliis the arrival time of thei^thcustomer. The arrival times are sorted in non-decreasing order.timeiis the time needed to prepare the order of thei^thcustomer.
When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits until the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.
Return the average waiting time of all customers. Solutions within 10^-5 from the actual answer are considered accepted.
Example 1
Input
customers = [[1,2],[2,5],[4,3]]Output
5The waiting times are 2, 6, and 7, so the average waiting time is (2 + 6 + 7) / 3 = 5.
Example 2
Input
customers = [[5,2],[5,4],[10,3],[20,1]]Output
3.25The waiting times are 2, 6, 4, and 1, so the average waiting time is (2 + 6 + 4 + 1) / 4 = 3.25.
Constraints
- 1 <= customers.length <= 10^5
- 1 <= arrivali, timei <= 10^4
- arrivali <= arrivali+1