Using SortedList
Code


# Code
```python3 []
from sortedcontainers import SortedList
class Solution:
    def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:
        rooms.sort(key=lambda x: -x[1])
        queries = sorted(enumerate(queries), key=lambda x: -x[1][1])
        
        res = [-1] * len(queries)
        valid_rooms = SortedList()
        i = 0  

        for idx, (room_id, min_size) in queries:
            while i < len(rooms) and rooms[i][1] >= min_size:
                valid_rooms.add(rooms[i][0])
                i += 1
            
            if not valid_rooms:
                continue
            
            pos = valid_rooms.bisect_left(room_id)
            candidates = []
            
            if pos < len(valid_rooms):
                candidates.append(valid_rooms[pos])  
            if pos > 0:
                candidates.append(valid_rooms[pos - 1])  
            
            res[idx] = min(candidates, key=lambda x: (abs(x - room_id), x))
        
        return res

```
['Python3']