How can I optimize this code, it is showing TLE
#include<bits/stdc++.h>
using namespace std;
class Hostel{
public:
int x;
int y;
Hostel(int x,int y){
this->x=x;
this->y=y;
}
int distance(){
return((xx) + (yy));
}
void print(){
cout<<distance()<<endl;
}
};
class HostelCompare{
public:
bool operator () (Hostel a, Hostel b){
return (a.distance()>b.distance());
}
};
int x[1000000],y[1000000];
int main() {
priority_queue<Hostel, vector, HostelCompare> pq1,pq2;
int k,k1,q,a,i=0; cin>>q>>k; k1=k;
while(q–){
cin>>a;
if(a==1){
cin>>x[i]>>y[i];
Hostel h(x[i],y[i]); i++;
pq1.push(h);
}
if(a==2){
k–;
while(k–){
Hostel h1=pq1.top();
pq2.push(h1);
pq1.pop();
} k=k1-1;
Hostel h=pq1.top();
h.print();
while(k–){
Hostel h2=pq2.top();
pq1.push(h2);
pq2.pop();
}
k=k1;
}
}
return 0;
}