In the question statement the rocket distance is given as (x2 - x1)2 + (y2 - y1)2 whereas sample output is calculating (x2 - x1)^2 + (y2 - y1)^2.
Also trying both cases, I am getting wrong answer for both test cases
Here is my code:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> p1,pair<int,int> p2){
return !(pow(p1.first,2)+pow(p1.second,2)>pow(p2.first,2)+pow(p2.second,2));
}
int main() {
int q,k,type,x,y;
vector<pair<int,int>> p;
cin>>q;
cin>>k;
for(int i=0;i<q;i++){
cin>>type;
if(type==1){
cin>>x;
cin>>y;
if(i==3){
sort(p.begin(),p.end(),comp);
}
if(i<3||comp(make_pair(x,y),make_pair(p[k-1].first,p[k-1].second))){
p.push_back(make_pair(x,y));
sort(p.begin(),p.end(),comp);
}
}else{
cout<<(p[k-1].first*2)+(p[k-1].second*2)<<"\n";
}
}
return 0;
}