[C++]  sort-based search
Approach 1: sort-based search [1]\nTime complexity: O(nlogn + mlogm);  where n = |rooms|, m = |queries|\nSpace complexity: O(n + m)\n\nSort queries and rooms by
Approach 1: sort-based search [1]\nTime complexity: O(nlogn + mlogm);  where n = |rooms|, m = |queries|\nSpace complexity: O(n + m)\n\nSort queries and rooms by size in descending order, only add valid rooms (size >= min_size) to the treeset for binary search.\n```\nclass Solution {\npublic:\n    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {\n        const int n = rooms.size(), m = queries.size();\n        for(int i = 0; i < m; i++) queries[i].push_back(i);\n        sort(begin(queries), end(queries), [](const auto& a, const auto& b){return a[1] > b[1];});\n        sort(begin(rooms), end(rooms), [](const auto& a, const auto& b){return a[1] > b[1];});\n        vector<int> ans(m, -1);\n        set<int> ids;\n        int j = 0;        \n        for(const auto& q: queries){\n            while(j < n && rooms[j][1] >=q[1]) ids.insert(rooms[j++][0]);\n            if(ids.empty()) continue;\n            int id = q[0];\n            auto it = ids.lower_bound(id);\n            int id1 = (it != end(ids) )? *it : INT_MAX;\n            int id2 = id1;\n            if(it != begin(ids)) id2 = *prev(it);\n            ans[q[2]] = abs(id1 - id) < abs(id2 - id) ? id1 : id2;\n        }\n        return ans;        \n    }\n};\n```\nReference:\n[1] https://zxi.mytechroad.com/blog/algorithms/binary-search/leetcode-1847-closest-room/
['C']