A bank has customers people waiting in a single line and M tellers, where M = len(service_times). Teller i takes service_times[i] minutes to serve one customer. All tellers are available starting at time 0, and each teller serves exactly one customer at a time.
Customers are served in line order. When a teller becomes free, the next customer in line goes to that teller and is served right away.
Return the time at which the last customer finishes being served, meaning the moment when every customer in the line has been served.
Function Signature
def last_customer_time(customers: int, service_times: list[int]) -> int:
Rules
-
All customers are in line at time 0, and nobody else arrives.
-
When several tellers are free at the same moment, the next customer goes to the free teller with the smallest index.
-
A customer who reaches teller i at time t finishes at t + service_times[i], and teller i is free again at that moment.
-
Return the largest finish time over all customers. Because tellers work at different speeds, it can belong to a customer who was not last in line (see Example 1).
Constraints
-
1 <= customers <= 10^5
-
1 <= len(service_times) <= 10^4
-
1 <= service_times[i] <= 100
Examples
Input: customers = 5, service_times = [3,5]
Output: 10
Customers 1 and 2 start at time 0 with tellers 0 and 1. Teller 0 is free at 3 and serves customer 3 until 6, teller 1 is free at 5 and serves customer 4 until 10, and teller 0 serves customer 5 from 6 to 9. The last service to end is customer 4's, at time 10.
Input: customers = 3, service_times = [1,2,3]
Output: 3
All three customers start at time 0 with different tellers and finish at 1, 2 and 3.
Input: customers = 4, service_times = [2,1]
Output: 4
Teller 0 serves customer 1 from 0 to 2, while teller 1 serves customer 2 from 0 to 1 and customer 3 from 1 to 2. At time 2 both tellers are free, so customer 4 goes to teller 0, the smaller index, and finishes at 4.