[Python3] greedy
\n\nfrom sortedcontainers import SortedList\n\nclass Solution:\n    def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:\n     
\n```\nfrom sortedcontainers import SortedList\n\nclass Solution:\n    def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:\n        rooms.sort(key=lambda x: (-x[1], x[0])) # descending order \n        \n        ans = [-1] * len(queries)\n        sl = SortedList()\n        k = 0 \n        \n        for (preferred, msz), i in sorted(zip(queries, range(len(queries))), key=lambda x: (-x[0][1], x[0][0])): # descending order \n            while k < len(rooms) and rooms[k][1] >= msz: \n                sl.add(rooms[k][0])\n                k += 1\n            v = sl.bisect_left(preferred)\n            if sl: \n                if v == len(sl) or v > 0 and preferred - sl[v-1] <= sl[v] - preferred: ans[i] = sl[v-1]\n                else: ans[i] = sl[v]\n        return ans \n```
['Python3']