Boss Point

Your are given N points in a plane, the coordinates of a Boss Point - (xBoss, yBoss) - and an integer K.

Find the K nearest points to the Boss Point and print them in order of ascending distance between them and the Boss Point.
If two points have same distance to Boss Point, print them in lexicographic order.


The first line contains integers N and K.
The second line contains the coordinates xBoss, yBoss.
Each of the following N lines contains the coordinates (xi, yi) of a point.


You should print the K nearest points to the Boss Point.


  • 1 ≤ N, K ≤ 104
  • -104 ≤ xBoss, yBoss, x, y ≤ 104
  • All points have integer coordinates.
  • The distance metric used in this problem is the Euclidean distance
  • A point (x1, y1) comes before (x2, y2) in lexicographic order if x1 < x2 || (x1 == x2 && y1 < y2)


3 2
0 0
2 2
-2 -2
1 1
1 1
-2 -2

Sponsors Gold