Author- Mahak Abroal

Tester- Akanksha Bigasia

Editorialist- Mahak Abroal

PROBLEM

In this question, there are two rods arranged in plus shaped, on which the balls are placed. We need to find

the maximum distance possible among all the balls present on the two rods placed in “plus-shaped” manner.

EXPLANATION

Since all the balls are present on the cross which can be viewed as the x-axis or y-axis. So, the co-ordinates can be as (x’,0) and (0,y’) for x-axis and y-axis respectively where x’ and y’ represent their respective position on x-axis and y-axis. Here the maximum distance will be one out of the following possible cases:

- The distance between the maximum and minimum co-ordinates of x-axis.
- The distance between the maximum and minimum co-ordinates of y-axis.
- The distance between the maximum co-ordinate of x-axis and minimum co-ordinate of y-axis.
- The distance between the maximum co-ordinate of y-axis and minimum co-ordinate of x-axis.
- The distance between the maximum co-ordinate of x-axis and maximum co-ordinate of y-axis.
- The distance between the minimum co-ordinate of x-axis and minimum co-ordinate of y-axis.

SOLUTION

```
#include < bits/stdc++.h >
typedef long long ll;
using namespace std;
ll max(ll a,ll b)
{ return a>b?a:b;}
int main() {
ll n, max_x=0, max_y=0;
ll y[100000],x[100000];
cin>>n;
for(ll i=0;i< n;i++)
cin>>x[i]>>y[i];
ll min_y=y[0], min_x=x[0];
max_x=x[0],max_y=y[0];
for(ll i=0;i < n;i++){
if(y[i]==0){
if(abs(x[i])>max_x) max_x=x[i];
if(abs(x[i]< min_x)) min_x=x[i];
}
else if(x[i]==0){
if(abs(y[i]>max_y)) max_y=y[i];
if(abs(y[i] < min_y)) min_y=y[i];
}
}
ll ans;
ans=max(sqrt(pow((max_x-min_x),2)),sqrt(pow((max_y-min_y),2)));
ans=max(ans,sqrt(max_x*max_x+min_y*min_y));
ans=max(ans,sqrt(max_y*max_y+min_x*min_x));
ans=max(ans,sqrt(min_x*min_x+min_y*min_y));
ans=max(ans,sqrt(max_y*max_y+max_x*max_x));
cout<< ans<< endl;
return 0;
}
```