JS | 3 MinHeaps (Beats 100%)
\n\n# Code\n\n/**\n * @param {number} k\n * @param {number[]} arrival\n * @param {number[]} load\n * @return {number[]}\n */\nvar busiestServers = function (k, 
![Screen Shot 2024-05-28 at 09.16.49.png](https://assets.leetcode.com/users/images/04ed8471-2678-4ed6-b35b-ce4d79f64405_1716859060.8064663.png)\n\n# Code\n```\n/**\n * @param {number} k\n * @param {number[]} arrival\n * @param {number[]} load\n * @return {number[]}\n */\nvar busiestServers = function (k, arrival, load) {\n    let occupied = new MinPriorityQueue();\n    let emptyServerAfterMOD = new MinPriorityQueue();\n    let emptyServerBeforeMOD = new MinPriorityQueue();\n    let timeUses = new Array(k).fill(0);\n\n    for (let i = 0; i < k; i++) {\n        emptyServerBeforeMOD.enqueue(i);\n    }\n\n    let max = 0;\n    for (let i = 0; i < arrival.length; i++) {\n        let mod = i % k;\n\n        if (mod === 0) {\n            [emptyServerBeforeMOD, emptyServerAfterMOD] = [emptyServerAfterMOD, emptyServerBeforeMOD];\n        }\n\n        while (occupied.front()?.priority <= arrival[i]) {\n            let newEmpty = occupied.dequeue().element;\n            newEmpty < mod ? emptyServerBeforeMOD.enqueue(newEmpty) : emptyServerAfterMOD.enqueue(newEmpty);\n        }\n\n        while (emptyServerAfterMOD.front()?.element < mod) {\n            emptyServerBeforeMOD.enqueue(emptyServerAfterMOD.dequeue().element);\n        }\n\n        let server = emptyServerAfterMOD.size() ?\n            emptyServerAfterMOD.dequeue().element :\n            (emptyServerBeforeMOD.size() ? emptyServerBeforeMOD.dequeue().element : -1);\n\n        if (server === -1) continue;\n        max = Math.max(++timeUses[server], max);\n        occupied.enqueue(server, arrival[i] + load[i]);\n    }\n\n    let ans = [];\n    for (let i = 0; i < k; i++) {\n        if (timeUses[i] === max) ans.push(i);\n    }\n\n    return ans;\n};\n```
['JavaScript']