Confidence Meter
A music app places listeners on a 2D taste map. It already knows a few listeners and whether they liked a song (1
) or not (0
). For a new listener position, the app looks at the k
closest known listeners using straight-line distance (Euclidean L2) and reports how confident it is: the percentage of those k
neighbors with label 1
.
You are asked to implement that feature in the app.

The first line of the input contains a single integer n
representing the number of known listeners.
The next n
lines each contain two floating-point numbers x y
followed by a label 0
or 1
, describing one listener’s position and whether they liked the song.
The next line contains a single integer k
(1 ≤ k ≤ n).
The next line contains a single integer q
representing the number of listener positions to check.
The last q
lines each contain two floating-point numbers x y
representing the coordinates of new listeners.
The program should print q
lines, each one representing the percentage of 1
s for each new listener.
Input | Output |
---|---|
5 | 66.66666666666667 |
4 | 75 |
4 | 25 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB