Python, bisect
\nimport bisect\nclass Solution:\n    def closestRoom(self, rooms, queries):\n        rooms = sorted([(j,i) for i ,j in rooms])[::-1]\n        queries = sorted(
```\nimport bisect\nclass Solution:\n    def closestRoom(self, rooms, queries):\n        rooms = sorted([(j,i) for i ,j in rooms])[::-1]\n        queries = sorted((k,j,i) for i,(j,k) in enumerate(queries))[::-1]\n\n        R= 0\n        Q = 0\n        aval = []\n        res = [-1] * len(queries)\n        while R <= len(rooms) and Q < len(queries):\n            \n            if R< len(rooms) and rooms[R][0] >= queries[Q][0]:\n                aval.append(rooms[R][1])\n                R+=1\n               \n            else:\n                if len(aval)!=0:\n                    aval.sort()\n                    f,s=float(\'inf\'),float(\'inf\')\n                    pref, qid = queries[Q][1] , queries[Q][2]\n                    i = bisect_left(aval,pref)\n                    if i>0:\n                        f=abs(pref-aval[i-1])\n                    if i < len(aval):\n                        s = abs(pref-aval[i])\n                    if f<=s:\n                        res[qid]=aval[i-1]\n                    else: \n                        res[qid]=aval[i]\n                Q+=1\n        return res\n```
['Python']