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)
before printing the answer
The link to the modified code :-


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

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.

see my earlier reply

I am also using the same approach but why does it show time limit exceeded when i am just using a sorting.
using namespace std;

int main()
int tc;
//int flag=0;
int n;
//node arr[n];
long double d1[n],d2[n];
for(int i=0;i<n;i++)
long double x;
long double y;

    long double min1=d1[1]-d1[0];
    long double min2=d2[1]-d2[0];
    for(int i=0;i<n-1;i++)


Help will be highly appreciated.

use fast i/o in your code

samarthtandon please elaborate

add these lines…

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 :frowning:

The min() function is only used to compare 2-integers, don’t use it, compare the numbers by yourself , using greater than condition :slight_smile:

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 :slight_smile: