1734. Priority Dispatch Desk
A repair desk employs several crews, where crew i has a cost rating weights[i]. Job j arrives at second j, needs durations[j] seconds of work and has an urgency priorities[j]. At any second, every waiting job is considered in order of higher urgency first (smaller index on a tie) and is given to the idle crew with the smallest rating (smaller index on a tie), until no job or no idle crew remains. A crew that starts a job at second t is idle again at second t + durations[j]. When jobs wait and every crew is busy, time skips to the next second at which a crew becomes idle.
Return an int[] giving the crew index assigned to each job. The clock can pass 2^31, so use 64-bit values. Expected: O((n + m) log(n + m)) time.
Example 1
- Input:
- weights = [3,1]durations = [4,1,1]priorities = [5,9,7]
- Output:
- [1,0,0]
- Explanation:
Job 0 takes the cheaper crew 1 (busy until second 4); job 1 uses crew 0 from second 1 to 2, and crew 0 is idle again when job 2 arrives at second 2.
Example 2
- Input:
- weights = [2,2,5]durations = [2,2,2,2]priorities = [1,1,1,1]
- Output:
- [0,1,0,1]
- Explanation:
Equal ratings break ties by crew index, so crews 0 and 1 are used first and crew 2 only when both are busy.
Constraints
1 ≤ weights.length, durations.length ≤ 105
durations.length == priorities.length
1 ≤ weights[i], durations[j] ≤ 105
1 ≤ priorities[j] ≤ 109
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
- Time per case
- Python 4,600 msC++ 1,150 msJava 2,300 msJavaScript 2,300 msTypeScript 2,300 ms
Expected complexity
- Time
- O((n + m) log(n + m))
- Space
- O(n + m)