Thanks for participating; we hope you enjoyed the tasks! Look at the bottom of this post for some more challenges.
Feel free to ask in the comment if you have any question. If you have a different solution from ours, share it too. :D
Can you do better than ?
There's a nice solution, but you could also use a Voronoi diagram for an runtime too!
Develop from our approach to solve the task in linear time!
Solve the task when m can be up to 105!