Hostel Visit (my code is failing 2nd test case)

Problem Name - Hostel Visit
2nd test case is giving wrong answer.
https://ide.codingblocks.com/s/72786

My its coming "TIme_Out " … Can someOne Please help !!!

#include <bits/stdc++.h>
using namespace std;
class point{
int x;
int y;
public:
point(){
this->x=0;
this->y=0;
}
point(int x,int y){
this->x=x;
this->y=y;
}
int distance(){
return xx+yy;
}
};
class compare{
public:
bool operator()(point x , point y){

      return  x.distance() > y.distance();
}

};

int main() {
int n,k;
cin>>n>>k;
priority_queue<point,vector,compare> pq;
for(int i=0;i<n;i++){
int temp;
cin>>temp;
if(temp==1){
int first,second;
cin>>first>>second;
point p(first,second);
pq.push§;
}
if(temp==2){
point pop_elements[k];
for(int j=0;j<k-1;j++){
pop_elements[j]=pq.top();
pq.pop();
}
point p = pq.top();
cout<<p.distance()<<endl;
for(int j=0;j<k-1;j++){
pq.push(pop_elements[j]);
}
}
}

return 0;

}

I am not able to optimize it … Please can you try ?? Is there any way to directly print the Kth smallest from priority_queue ??? that may reduce time !!!

@Ayush_shaz

can you please create a different post so that i can help both of you in better way
, and also please paste link of your code (coding blocks ide)

1 Like

@chwanshu27

your code is correct just use long long for x and y also

Hit like if you get it!
Cheers!

1 Like

Thanks, it worked!
But problem says x, y lie between (-10^6, 10^6). Why does it even need long long?

May be ±10^9 tk hoga some constraint error!
That is why

I hope I’ve cleared your doubt. I ask you to please rate your experience here 1
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.