
1) All the coordinates are integral coordinates on the X-Y plane.
2) The distance between any two coordinates is the euclidean distance.
3) There can be multiple offices located on the same coordinate.
4) You are allowed to build the ninja headquarters on the coordinate having ninja offices.
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains a single integer, ‘N’, where ‘N’ denotes the number of ninja offices.
The second line of each test case contains a single integer, ‘range’, where ‘range’ denotes the maximum distance in which each office can provide its services.
The next ‘N’ lines of each test case contain three space-separated integers, ‘X’, ‘Y’, and ‘val’, where (‘X’, ‘Y’) denotes the coordinate where the ninja office is located, and ‘val’ denotes the value associated with that office.
For each test case, print the integral coordinate where the sum of the number of services offered by each office is the maximum.
If there are multiple coordinates with the same number of services, print the lexicographically minimum coordinate.
A coordinate (X1, Y1) is lexicographically smaller than (X2, Y2) if either X1 is less than X2 or X1 is the same as X2 and Y1 is less than Y2.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 25
0 <= X[i], Y[i] <= 25
0 <= val[i] <= 10 ^ 5
1 <= range <= 30
Time Limit: 1Sec
The idea here is to use the fact that the number of services offered by any office decreases as the distance from the office increases. Firstly, we will find the maximum value of X - coordinate and Y - coordinate among all the coordinates where the ninja office is located, say ‘maxX’ and ‘maxY’, respectively. Now we will compute the sum of the number of services offered by each office for all the coordinates whose X - coordinate is from 0 to ‘maxX’ inclusive and Y - coordinate is from 0 to ‘maxY’ inclusive. Among all coordinates, we will take the coordinate having the maximum sum of the number of services offered by each company and is lexicographically smallest.
The idea here is to do a Breadth-first search from all the coordinates where ninja offices are located. As the number of services offered by any office decreases as the distance from the office increases, we will start our BFS from all the coordinates of ninja offices. Now, for each coordinate in our BFS, we will compute the sum of the number of services offered by each office at that coordinate. If the computed sum is the maximum sum so far, we will consider that coordinate as our potential answer and do a BFS on its neighbor coordinates.