[Swift] Heap O(nlogn*logk)
See details explaination from this article\nhttps://leetcode.com/problems/find-servers-that-handled-most-number-of-requests/discuss/876883/Python-using-only-hea
See details explaination from this article\nhttps://leetcode.com/problems/find-servers-that-handled-most-number-of-requests/discuss/876883/Python-using-only-heaps\n\nBelow is Swift version\n```\nclass Heap<T> {\n    private var data: [T] = []\n    var count: Int {\n        return data.count\n    }\n    private var sort: ((T, T) -> Bool)!\n    init (_ sort: @escaping ((T, T) -> Bool)) {\n        self.sort = sort\n    }\n    private func p(_ i: Int) -> Int { return (i - 1) / 2 }\n    private func l(_ i: Int) -> Int { return i * 2 + 1 }\n    private func r(_ i: Int) -> Int { return i * 2 + 2 }\n    func isEmpty() -> Bool {\n        return data.isEmpty\n    }\n    func add(_ val: T) {\n        data.append(val)\n        swim(data.count - 1)\n    }\n    private func swim(_ i: Int) {\n        if sort(data[i], data[p(i)]) {\n            data.swapAt(i, p(i))\n            swim(p(i))\n        }\n    }\n    func remove() -> T? {\n        if data.count == 0 { return nil }\n        if data.count == 1 { return data.removeLast() }\n        let node = data[0]\n        data[0] = data.removeLast()\n        dive(0)\n        return node\n    }\n    private func dive(_ i: Int) {\n        let left = l(i) >= data.count ? data[i] : data[l(i)]\n        let right = r(i) >= data.count ? data[i] : data[r(i)]\n        if sort(left, data[i]) || sort(right, data[i]) {\n            if sort(left, right) {\n                data.swapAt(i, l(i))\n                dive(l(i))\n            } else {\n                data.swapAt(i, r(i))\n                dive(r(i))\n            }\n        }\n    }\n    func top() -> T? {\n        return data.first\n    }\n}\n\nclass Solution {\n    // Time: O(nlogn * logk) n is number of request, k is number of servers\n    // Space: O(n+k)\n    func busiestServers(_ k: Int, _ arrival: [Int], _ load: [Int]) -> [Int] {     \n        // store current server are working, stored by end time\n        var sessions = Heap<(Int,Int)> { $0.0 < $1.0 } \n        \n        // store server of current round\n        var currentRound = Heap<Int> { $0 < $1 }\n        \n        // store server of next round\n        var nextRound = Heap<Int> { $0 < $1 }\n        for i in 0..<k {\n            nextRound.add(i)\n        }\n        \n        // record how many request of a server executed\n        var timesheet = Array(repeating: 0, count: k)\n        \n        // map into requests (startTime, duration)\n        var requests: [(Int, Int)] = []\n        for i in 0..<arrival.count {\n            requests.append((arrival[i], load[i]))\n        }\n        \n        // start requesting...\n        for (index, (startTime, duration)) in requests.enumerated() {\n            let roundRobinServer = index % k\n            // it is time to go back\n            if roundRobinServer == 0 {\n                currentRound = nextRound\n                nextRound = Heap<Int> { $0 < $1 }\n            }\n            \n            // releases servers which already done executing previous requests\n            while sessions.count > 0 && sessions.top()!.0 <= startTime {\n                let freeServer = sessions.remove()!.1\n                \n                // if server is free is < roundRobinServer, so it should be added to next round (current round more priority)\n                if freeServer < roundRobinServer {\n                    nextRound.add(freeServer)\n                } else {\n                    currentRound.add(freeServer)\n                }\n            }\n            \n            // now just pick a server from current round\n            var chosenServer = -1\n            if currentRound.count > 0 {\n                chosenServer = currentRound.remove()!\n            // if current round is out of server, consider to next round\n            } else if nextRound.count > 0 {\n                chosenServer = nextRound.remove()!\n            }\n            \n            // if no server is availble, drop that\n            if chosenServer == -1 {\n                continue\n            }\n            \n            // increment for the server execute this request\n            timesheet[chosenServer] += 1\n            // ... and add it into session\n            sessions.add((startTime + duration, chosenServer))\n        }\n        \n        // find out the maximum requests and all server has same amount\n        var ans: [Int] = []\n        var maxRequest = 0\n        for server in 0..<timesheet.count {\n            if maxRequest < timesheet[server] {\n                maxRequest = timesheet[server]\n                ans = []\n            }\n            if maxRequest == timesheet[server] {\n                ans.append(server)\n            }\n        }\n        \n        return ans\n    }\n}\n```
[]