Tap here to switch tabs
Problem
Submissions

Problem: Process Tasks Using Servers

med
30 min
Try to solve the Process Tasks Using Servers problem.

Statement

You are given two 00 indexed integer arrays servers and tasks of lengths n and m respectively. The value servers[i] represents the weight of the iextthi^{ ext{th}} server, and tasks[j] represents the time required to process the jextthj^{ ext{th}} task.

Tasks are assigned according to the following rules:

At second j, the jextthj^{ ext{th}} task arrives and is placed into a queue, starting from task 00 at second 00 through task m−1m - 1 at second m−1m - 1.

While there are tasks in the queue and available servers, the task at the front of the queue is assigned to an available server that has the smallest weight. In the event of a tie, the server with the smallest index is chosen.

If no servers are available, the task remains in the queue until a server finishes its current task.

If multiple tasks are waiting in the queue when servers become available, they are processed in order of their arrival.

A server assigned task j at time t becomes free again at time t+t + tasks[j].

Return an array ans of length m, where ans[j] is the index of the server assigned to process the jextthj^{ ext{th}} task.

Constraints:

  • servers.length =n= n

  • tasks.length =m= m

  • 1≤n,m≤2imes1051 \leq n, m \leq 2 imes 10^5

  • 1≤1 \leq servers[i], tasks[j] ≤2imes105\leq 2 imes 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Process Tasks Using Servers

med
30 min
Try to solve the Process Tasks Using Servers problem.

Statement

You are given two 00 indexed integer arrays servers and tasks of lengths n and m respectively. The value servers[i] represents the weight of the iextthi^{ ext{th}} server, and tasks[j] represents the time required to process the jextthj^{ ext{th}} task.

Tasks are assigned according to the following rules:

At second j, the jextthj^{ ext{th}} task arrives and is placed into a queue, starting from task 00 at second 00 through task m−1m - 1 at second m−1m - 1.

While there are tasks in the queue and available servers, the task at the front of the queue is assigned to an available server that has the smallest weight. In the event of a tie, the server with the smallest index is chosen.

If no servers are available, the task remains in the queue until a server finishes its current task.

If multiple tasks are waiting in the queue when servers become available, they are processed in order of their arrival.

A server assigned task j at time t becomes free again at time t+t + tasks[j].

Return an array ans of length m, where ans[j] is the index of the server assigned to process the jextthj^{ ext{th}} task.

Constraints:

  • servers.length =n= n

  • tasks.length =m= m

  • 1≤n,m≤2imes1051 \leq n, m \leq 2 imes 10^5

  • 1≤1 \leq servers[i], tasks[j] ≤2imes105\leq 2 imes 10^5