About hotel visit question time limit getting exceeded

Sir my time limit is getting exceeded in hotel visit problem please check my submission and tell where is the problem

#include
#include
#include
using namespace std;
int main() {
vector distances;
int n;
int k;
cin>>n>>k;
distances.reserve(n);
for(int i=0;i<n;i++){
int type,x,y,distance;
cin>>type;
if(type==1){
cin>>x>>y;
distance=xx+yy;
distances.push_back(distance);
}
else if(type==2){
sort(distances.begin(),distances.end());
cout<<distances[k-1]<<endl;
}
}
return 0;
}

actually you are sorting again and again for every query of type 2 , therefore it will result in tle,
HINT is to use priority queue