Sort the rooms and queries by roomSize
Code

# Code
```cpp []
class Solution {
public:
    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {
        int n = rooms.size(), k = queries.size();
        for (int i = 0; i < n; ++i) {
            reverse(rooms[i].begin(), rooms[i].end());
        }
        for (int i = 0; i < k; ++i) {
            reverse(queries[i].begin(), queries[i].end());
            queries[i].push_back(i);
        }
        sort(rooms.begin(), rooms.end());
        sort(queries.begin(), queries.end());
        
        vector<int> res(k, -1);
        set<int> inds;
        for (int i = 0; i < n; ++i) {
            inds.insert(rooms[i][1]);
        }
        int i = 0;
        for (auto& qu : queries) {
            int minSz = qu[0], id = qu[1], j = qu[2];
            while (i < n && rooms[i][0] < minSz) {
                inds.erase(rooms[i++][1]);
            }
            if (inds.empty()) break;
            if (id <= *inds.begin()) {
                res[j] = *inds.begin();
            } else if (id >= *inds.rbegin()) {
                res[j] = *inds.rbegin();
            } else {
                auto it1 = inds.lower_bound(id);
                auto it2 = it1;
                if (it2 != inds.begin()) {
                    --it2;
                }
                res[j] = (abs(id - *it1) < abs(id - *it2) ? *it1 : *it2);
            }
        }

        return res;
    }
};
```
['C++']