Show Your Sources
A museum curator is mapping known references on a flat board. When a new artwork arrives, the curator wants to list which references were closest to it.
Your job is to report the indices of the k
nearest references for each artwork, using straight-line distance.

The first line of the input contains a single integer n
representing the number of references on the board.
The next n
lines each contain two floating-point numbers x y
describing one reference’s position. References are indexed starting from 1 in the order they appear.
The next line contains a single integer k
representing how many neighbors to list per artwork.
The next line contains a single integer q
representing the number of artworks to check.
The last q
lines each contain two floating-point numbers x y
for an artwork’s position.
For each artwork, print k
space-separated indices of the nearest references in order of increasing Euclidean (L2) distance. If several references are exactly tied in distance, the smaller index comes first.
Input | Output |
---|---|
4 | 1 2 |
4 | 2 4 1 |
3 | 1 2 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB