I wrote a solution for HOSTEL VISIT problem but i am getting tle in 2nd test case, can anyone get in touch with me so that i can show my code and improvise it…
#include<bits/stdc++.h>
using namespace std;
class hostel{
public:
long long int x;
long long int y;
hostel(){
}
hostel(long long int x, long long int y){
this->x = x;
this->y = y;
}
int dist(){
return (x*x) + (y*y);
}
void print(){
cout<<(x*x)+(y*y)<<endl;
}
};
class dishostel{
public:
bool operator()(hostel h, hostel ht){
return h.dist()>ht.dist();
}
};
int main(){
long long int q,k,type_q;
long long int x,y;
priority_queue<hostel,vector<hostel>,dishostel> pq;
cin>>q>>k;
hostel hos[k];
for(long long int i=0;i<q;i++){
cin>>type_q;
if(type_q==1){
cin>>x>>y;
hostel h(x,y);
pq.push(h);
}
if(type_q==2){
for(int i=0;i<k;i++){
hos[i] = pq.top();
pq.pop();
}
hos[k-1].print();
for(int i=0;i<k;i++){
pq.push(hos[i]);
}
}
}
return 0;
}
Thank you

