Server i has weight servers[i]. Task j arrives at time j and takes tasks[j] seconds to finish once assigned. Initially every server is free.
Process tasks in arrival order. Assign the next waiting task to the free server with the smallest weight, breaking ties by smaller server index. If every server is busy, wait until the earliest completion time. Servers that finish at a given time are available for assignments at that same time. When several servers finish together, consider all of them before applying the weight and index priorities.
Return an array where entry j is the index of the server assigned to task j.
Example 1:
Input: servers = [2,1]
tasks = [3,2,1]
Output: [1,0,1]Explanation: Task 0 starts on server 1 at time 0. Task 1 starts on server 0 at time 1. Both servers finish at time 3, so waiting task 2 goes to server 1, which has the smaller weight.
Example 2:
Input: servers = [4,4]
tasks = [2,1,1]
Output: [0,1,0]Explanation: At time 0, equal weights are broken by index, so task 0 uses server 0. Task 1 uses server 1 at time 1. Both finish at time 2; server 0 wins the tie again for task 2.
Example 3:
Input: servers = [1]
tasks = [5,1,2]
Output: [0,0,0]Explanation: Only server 0 exists. The tasks start at times 0, 5, and 6, so all three assignments are 0. Tasks wait in arrival order while the server is busy.
Constraints:
1 <= servers.length <= 2000001 <= tasks.length <= 2000001 <= servers[i] <= 2000001 <= tasks[j] <= 200000