K Closest Points to Origin, then Path Feasibility

HARD · C · 3000ms

For a promotional stunt, Antu picks the K bus stops closest to the depot (by straight-line distance) and wants to know if all K stops can be visited via short connecting hops (distance ≤ D) without leaving any stop stranded. Given N 2D points and integer K, first find the K points closest to the origin (Euclidean distance). Then, treating those K points as nodes fully connected to each other (edge exists if Euclidean distance ≤ D, a given threshold), print "YES" if all K points form a single connected component, else "NO".

Input

Line1: N K D. Next N lines: x y.

Output

"YES" or "NO".

Constraints

1 ≤ K ≤ N ≤ 2000

Sample Input

4 3 5
0 0
3 4
1 1
100 100

Sample Output

YES
main.c
Loading editor…

Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.

K Closest Points to Origin, then Path Feasibility · DIU ContestHub