Thermostat Reality Check
A building’s thermostat sometimes spits out impossible readings below L
or above U
. Before your system compares readings with k-NN, it first pulls them back to reality so neighbors are judged fairly.

You are asked to read an initial set of readings with targets, then answer queries using k-NN Regression, where all features are confined to [L, U] before comparison. Predictions are the mean of the k nearest targets under the standard Euclidean distance. If several candidates are at the same distance around the cutoff, pick the item that appears earlier in the input. You may assume n ≥ k.
The first line of the input contains five values n d k L U
. Each of the next n
lines contains d
floating-point numbers followed by a floating-point target.
The next line contains a single integer q
representing how many new readings to predict. Each of the next q
lines contains d
floating-point numbers to compare against the initial set after applying the same clipping rule.
The program should print q
lines. Each line should contain a single floating-point number - the predicted target.
Input | Output |
---|---|
4 1 2 0 10 | 0 |
5 2 3 0 10 | 6.8333333333 |
6 1 3 0 10 | 1.6666666667 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB