C++ | Binary Search | O(N*(K+LogN)) Solution
\nclass Solution {\npublic:\n    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {\n        int n = rooms.size();\n        sor
```\nclass Solution {\npublic:\n    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {\n        int n = rooms.size();\n        sort(rooms.begin(), rooms.end(), [] (const vector<int>& a, const vector<int>& b) {\n            return a[1] < b[1];\n        });\n        int k = queries.size();\n        vector<int> output;\n        for(int i = 0; i < k; i++) {\n            int pref = queries[i][0];\n            int minSize = queries[i][1];\n            int lo = -1, hi = n-1;\n            while(hi - lo > 1) {\n                int mid = lo + (hi-lo)/2;\n                if (rooms[mid][1] >= minSize) {\n                    hi = mid;\n                } else {\n                    lo = mid;\n                }\n            }\n            int idx = lo+1;\n            if (rooms[idx][1] < minSize) {\n                output.push_back(-1);\n                continue;\n            }\n            int diff = abs(rooms[idx][0] - pref);\n            int val = idx;\n            for(int j = idx; j<n; j++) {\n                int currDiff = abs(rooms[j][0]- pref);\n                if(currDiff < diff) {\n                    val = j;\n                    diff = currDiff;\n                } else if (currDiff == diff && rooms[j][0] < rooms[val][0]) {\n                    val = j;\n                    diff = currDiff;\n                }                    \n            }\n            \n            output.push_back(rooms[val][0]);\n        }\n        return output;\n    }\n};\n```
[]