Binary Search
\nclass Solution {\npublic:\n    vector<int> closestRoom(vector<vector<int>>& rm, vector<vector<int>>& q) \n    {\n        for(int i=0;i<rm.size();i++)\n       
```\nclass Solution {\npublic:\n    vector<int> closestRoom(vector<vector<int>>& rm, vector<vector<int>>& q) \n    {\n        for(int i=0;i<rm.size();i++)\n            swap(rm[i][0],rm[i][1]);\n        sort(rm.begin(),rm.end(),greater<vector<int>>());\n        for(int i=0;i<q.size();i++)\n            q[i].push_back(i),swap(q[i][0],q[i][1]);\n        sort(q.begin(),q.end(),greater<vector<int>>());\n        vector<int> ans(q.size());\n        set<int> s;\n        for(int i=0,j=0;j<q.size();j++)\n        {\n            while(i<rm.size() && rm[i][0]>=q[j][0])\n                s.insert(rm[i][1]),i++;\n            \n            auto it=s.lower_bound(q[j][1]);\n            auto tp=it;\n            int d1=1e9,d2=1e9;\n            if(it!=s.end()) d2=(*it)-q[j][1];\n            if(it!=s.begin()) --it,d1=q[j][1]-(*it);\n            \n            if(d1==1e9 && d2==1e9) ans[q[j][2]]=-1;\n            else if(d1<=d2) ans[q[j][2]]=(*it);\n            else ans[q[j][2]]=(*tp);\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'C', 'C++']