For every house-spy pair with coordinates (xh,yh)and (xs,ys), calculate the distance as ∣xh−xs∣+∣yh−ys∣. All pairwise distances can be computed this way in quadratic time.
Note that if the size of the grid is N×N, there are at most O(N2)houses and spies. So, computing all pairwise distances can be done in O(N4), which is fast enough to fit in the time limit.
Now, for each spy, compute the distance to the closest house. Report the minimum such value.