Regarding HOSTEL VISIT problem

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;

}

firstly use long long it as square wont fit into int data structure.
watch this:-

1 Like

Thank you @apaarkamal for helping me fix my code!!

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.