Hostel Visit:Getting tle

giving tle how to optimize
ques:https://online.codingblocks.com/app/player/74266/content/76609/5368/code-challenge
code:https://ide.codingblocks.com/s/239324

hi @bhaskar0_0

this will definitely give TLE as you are sorting in each query
time complexity O(Q N logN )
which is very expensive

second thing is
you are storing all distance but you only k distances are sufficent to ans the question

use multiset to solve this problem

REFERENCE CODE(if needed)