Heaps:Closest to origin,solution not passing any test case

  #include <iostream>
  #include <queue>
  #include <stack>
 using namespace std;
 class Distance{
    public:
    int dist;
    int x;
    int y;
  Distance(int dist,int x,int y){
     this->dist=dist;
    this->x=x;
    this->y=y;
}

};

 class  DistCompare {
   public:
     bool operator()(Distance d1,Distance d2)
  { 
     if(d1.dist==d2.dist)
      return d1.x<d2.x;

        return d1.dist<d2.dist;
   }

};

   int main(){
      int n,k;

priority_queue<Distance,vector,DistCompare> pq;

       cin>>n;
pair<int,int> arr[n];
for(int i=0;i<n;i++)
{
     int x,y ;
    cin>>x>>y;
    
      arr[i]=make_pair(x,y);
}

cin>>k;

  for(int i=0;i<n;i++)
{ 
   int x=arr[i].first;
  int y=arr[i].second;
  int dist=x*x+y*y;
 Distance d(dist,x,y);
     if(pq.size()<k)
     {
       pq.push(d);
     }
    else if(pq.size()==k)
  {
       auto cDist=pq.top();
       int dd=cDist.dist;
       if(dist<dd)
      {
          pq.pop();
        pq.push(d);
    }
}

}

  while(!pq.empty())
 {
       Distance d=pq.top();
    cout<<d.x<<" "<<d.y<<endl;
    pq.pop();

}

return 0;

}

Please save your code on ide.codingblocks.com and then share its link.

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.