1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| class Solution: def busiestServers(self, ks: int, a: List[int], d: List[int]) -> List[int]: from sortedcontainers import SortedList ans = [0] * ks pq = [] fu = SortedList(range(ks)) v = 0 for i, j in zip(a, d): heappush(pq, [i, 1, i + j, v]) v += 1 while pq: i, k, j, num = heappop(pq) if k == 1 and fu: v = fu.bisect_left(num % ks) if v == len(fu): v = 0 v = fu[v] fu.remove(v) ans[v] += 1 heappush(pq, [j, 0, v, num]) elif k == 0: fu.add(j) t = max(ans) return [i for i in range(ks) if ans[i] == t]
|