Basically the problem is a variation of the Nearest neighbor search problem. A naive solution will take O(goblin * missiles) time, and be too slow. However, if we create a reasonably smart datastructure we can reduce the time significantly by only looking at goblins which are close in the x or y dimention. One simple way to do it is to first split the search space in horizontal or vertical stripes. Then, for each stripe, we can identify and eliminate the goblins in log(goblins), by binary searching for the highest and lowest gobline to be eliminated, giving a time complexity of missiles*log(goblins).