Question:
You are tasked with simulating a supermarket self-checkout system.
The supermarket has N checkout counters, each with its own queue.
Customers arrive one by one, each with a certain number of items.
A counter processes one item per minute.
Rules:
1. A customer always chooses the counter with the shortest queue length (if there’s a tie, choose the one with the smallest counter ID).
2. When a customer is being served, their remaining items decrease by 1 each minute.
3. If a counter’s queue becomes empty, it is immediately available for the next arriving customer.
Input:
• N — number of checkout counters.
• A list of customers, where each customer is represented as (arrival_time, items).
Output:
• A list showing the finish time for each customer in the order they arrived.
N = 2
Customers = [(0, 5), (0, 2), (1, 3), (4, 1)]
Output: [5, 2, 6, 5]
Explanation:
• Time 0: Customer 1 goes to Counter 1, Customer 2 goes to Counter 2.
• Time 1: Customer 3 arrives, joins Counter 2 (shorter queue).
• Time 4: Customer 4 arrives, joins Counter 1 (shorter queue).