Efficient JS solution - Segment tree (Beat 100% both time and memory)
\n\nPro tip: Love lil Xi\xE8 \uD83D\uDC9C \u7231\u5C0F\u8C22 \uD83D\uDC9C\nEvery gangsta\'s using heap!!!\n\n# Complexity\n- let n = arrival.length = load.lengt
![image.png](https://assets.leetcode.com/users/images/fa8f32fe-a19b-4f1f-896b-7dd5e64be45f_1705729520.0737376.png)\n\nPro tip: Love lil Xi\xE8 \uD83D\uDC9C \u7231\u5C0F\u8C22 \uD83D\uDC9C\nEvery gangsta\'s using heap!!!\n\n# Complexity\n- let `n = arrival.length = load.length`.\n- Time complexity: $$O((n + k)logk)$$\n- Space complexity: $$O(n + klogk)$$\n\n# Code\n```js\nclass IntervalTree {\n  constructor() {\n    /** @type {number} */\n    this.n = 0;\n\n    /** @type {number[]} */\n    this.mins = new Uint32Array(4e5);\n  }\n\n  reset(n) {\n    this.n = n;\n    this.mins.fill(0, 0, n << 2);\n  }\n\n  set(qi, v, ri, l, r) {\n    if (qi > r || qi < l) return;\n\n    if (r == l) {\n      this.mins[ri] = v;\n    } else {\n      let m = (l + r) >> 1;\n      let lc = (ri << 1) + 1;\n      let rc = lc + 1;\n\n      if (qi <= m) this.set(qi, v, lc, l, m);\n      else this.set(qi, v, rc, m + 1, r);\n\n      this.mins[ri] = Math.min(this.mins[lc], this.mins[rc]);\n    }\n  }\n\n  first(v, ql, qr, ri, l, r) {\n    if (ql > r || qr < l) return;\n    if (l == r) {\n      if (this.mins[ri] <= v) return l;\n      return;\n    }\n\n    let m = (l + r) >> 1;\n    let lc = (ri << 1) + 1;\n    let rc = lc + 1;\n\n    let res;\n    if (this.mins[lc] <= v) {\n      res = this.first(v, ql, qr, lc, l, m);\n    }\n    if (res == undefined && this.mins[rc] <= v) {\n      res = this.first(v, ql, qr, rc, m + 1, r);\n    }\n\n    return res;\n  }\n\n  cyclicFirst(v, s) {\n    return (\n      this.first(v, s, this.n - 1, 0, 0, this.n - 1) ??\n      this.first(v, 0, s - 1, 0, 0, this.n - 1)\n    );\n  }\n}\n\nlet cnt = new Uint32Array(1e5);\nlet it = new IntervalTree();\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  it.reset(k);\n  let n = arrival.length;\n\n  let max = 0;\n  cnt.fill(0, 0, k);\n  for (let i = 0; i < n; ++i) {\n    let p = it.cyclicFirst(arrival[i], i % k);\n    if (p == undefined) continue;\n    it.set(p, arrival[i] + load[i], 0, 0, k - 1);\n    max = Math.max(max, ++cnt[p]);\n  }\n\n  let res = [];\n  for (let i = 0; i < k; ++i) if (cnt[i] == max) res.push(i);\n  return res;\n};\n```
['Segment Tree', 'JavaScript']