C++ solution. sort the query by room size.
\n#### Idea\n- Because we need the room which has minSize by the given query, so we can iterate from the largest minSize query and put all the valid room to an 
\n#### Idea\n- Because we need the room which has minSize by the given query, so we can iterate from the largest minSize query and put all the valid room to an ordered set, and then do binary search to get room id in the ordered set.\n\n#### Complexity\n- Time O(max(nLog(n), mLog(m))) n is rooms length, m is queries length.\n- Space O(n)\n\n#### Solution\n- C++\n```\nclass Solution {\npublic:\n    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {\n        for(int i = 0; i < queries.size(); i++) queries[i].push_back(i);\n\n        sort(queries.begin(), queries.end(), [](auto &a, auto &b) {\n            \n            return a[1] > b[1];\n        });\n        sort(rooms.begin(), rooms.end(), [](auto &a, auto &b){\n            return a[1] > b[1];\n        });\n        int i = 0;\n        set<int> st;\n        vector<int> ans(queries.size());\n        for(auto q : queries) {\n            int prefer = q[0], minSize = q[1], idx = q[2];\n            while(i < rooms.size() && rooms[i][1] >= minSize)\n                st.insert(rooms[i++][0]);\n            if(st.size()) {\n                auto it = st.upper_bound(prefer);\n                int res = it != st.end() ? abs(*it - prefer) : INT_MAX;\n                int resRoomId = it != st.end() ? *it : INT_MAX;\n                if(it != st.begin()) {\n                    --it;\n                    if(abs(*it - prefer) <= res)\n                        resRoomId = *it;\n                }\n                ans[idx] = resRoomId;\n            }else\n                ans[idx] = -1;\n        }\n        return ans;\n    }\n};\n```
[]