Hostel Visit problem(TLE error is being shown)

I have solved the hostel visit problem but i am facing TLE error
Here is the code: Please point out my mistake
#include
#include

using namespace std;
int main(){
int q;
cin>>q;
int k;
cin>>k;
set distance;
int result[q];
for (int i=0;i<q;i++){
result[i] = -1;
}
int two_count = 0;
int count = 0;
while(q–){
int choice ;
cin>>choice;
if (choice ==1){
count += 1;
int x,y;
cin>>x>>y;
int dist = xx+yy;
distance.insert(dist);
}
else if (choice ==2){
auto it = distance.begin();
advance(it,k-1);
result[two_count] = *it;
two_count += 1;
}

}

for(int i = 0;i<two_count ;i++){
    cout<<result[i]<<endl;
}
return 0;

}

please share code in cb ide

@neil_gautam you can use a priority queue to solve this question

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.