#include<bits/stdc++.h>

using namespace std;

int main(){

int n,k;
cin>>n>>k;

unordered_map<int,int> nc;
priority_queue<pair<int,pair<int,int>>> maxhp;
int a[n][2];
for(int i=0;i<n;i++){
  cin>>a[i][0]>>a[i][1];
  int d=(pow(a[i][0],2)+pow(a[i][1],2));
  maxhp.push({d,{a[i][0],a[i][1]}});
  if(maxhp.size()>k){
      maxhp.pop();
  }
}
while(maxhp.size()>0){
  auto it=maxhp.top().second;
  cout<<it.first<<" "<<it.second<<endl;
  maxhp.pop();
}

return 0;
}


Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: