Python, sort solution with explanation
For each query, size of the candidate rooms >= size_q, we can find the candidate room from the bigger to smaller size.\n2. we can sort query by its size, and st
1. For each query, size of the candidate rooms >= size_q, we can find the candidate room from the bigger to smaller size.\n2. we can sort query by its size, and start with the query with the biggest size_q\n3. put ID of all the candidate room into BST, and use binary seach to find the room with smallest abs(room id - id_q).\ntc is O(mlogm + nlogn + nlogm), sc is O(m+n).\n\n\n```python\nINF = int(1e9)\nfrom sortedcontainers import SortedList\nclass Solution:\n    def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:\n        m, n = len(rooms), len(queries)\n        arr_room = sorted(range(m), key=lambda x: rooms[x][1], reverse=True)\n        arr_q = sorted(range(n), key=lambda x: queries[x][1], reverse=True)\n        ans = [-1] * n\n        bst = SortedList()\n        i = 0\n        for x in arr_q:\n            pref, size = queries[x]\n            while i < m and rooms[arr_room[i]][1] >= size:\n                bst.add(rooms[arr_room[i]][0])\n                i += 1\n            if bst:\n                pos = bst.bisect_left(pref)\n                cand1, cand2 = bst[pos] if pos < len(bst) else INF, bst[pos-1] if pos > 0 else INF\n                ans[x] = cand1 if abs(cand1 - pref) < abs(cand2 - pref) else cand2\n        return ans\n```
['Binary Search Tree', 'Sorting', 'Python']