 # Help me Debug WTBTR

There is some small mistake in my code. Help will be appreciated.
I have first applied the transformation (x,y) goes to (x-y,x+y) . This rotates the plane anticlockwise by 45 deg. This also scales the grid so that the multiplication by sqrt(2) is not needed at the end.
Then I sort first using the first coordinate and find the minimum difference and do the same for the second coordinate. Half of the minimum of these two is the answer.

1 Like

you need to sort x and y axis saperately…

Just add the line :- cout.precision(30)
The link to the modified code :- https://ideone.com/nZ2J2f

2 Likes

That was it. I feel silly getting the logic right and then not printing the solution correctly

1 Like

Take care the next time.

1 Like

here is my solution

https://www.codechef.com/viewsolution/24272229

I think setting precision to 30 is not a good idea just use this instead

cout << fixed;

1 Like

Why is it better than setting precision to 30 @samarthtandon? Also I am sorting along the x and y co-ordinates separately.

I am also using the same approach but why does it show time limit exceeded when i am just using a sorting.
#include<bits/stdc++.h>
using namespace std;

int main()
{
int tc;
cin>>tc;
//int flag=0;
while(tc–)
{
int n;
cin>>n;
//node arr[n];
long double d1[n],d2[n];
for(int i=0;i<n;i++)
{
long double x;
long double y;
cin>>x>>y;
d1[i]=y-x;
d2[i]=y+x;
}

``````    sort(d1,d1+n);
sort(d2,d2+n);
long double min1=d1-d1;
long double min2=d2-d2;
for(int i=0;i<n-1;i++)
{
if(d1[i+1]-d1[i]<min1)min1=d1[i+1]-d1[i];
if(d2[i+1]-d2[i]<min2)min2=d2[i+1]-d2[i];
}
min1=min(min1,min2)/2;
cout.precision(30);
cout<<min1<<endl;

}
``````

}

Help will be highly appreciated.

use fast i/o in your code

ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);

1 Like

Fast i/o won’t work as his code gives WA for most of the test-cases and not TLE The min() function is only used to compare 2-integers, don’t use it, compare the numbers by yourself , using greater than condition I don’t know but he said he is getting TLE
??

thnx samarth! it’s working now

Oops, I saw your code which had WA in big test-cases,in actual-contest, so thought you should get AC in those cases first, then remove TLE, ALWAYS USE FASTI IO 