Cauldron Classifier: Skim the Gremlins, Ask Five
In the Potion Lab, three sensors watch each brew: hue, temperature, and viscosity. Sometimes a gremlin bumps a dial, and readings fly out of the realm of plausible potions. Your sorter should ignore impossible measurements and then ask the closest five known brews what the new sample most resembles.

You are asked to read an initial list of labeled brews, use the given valid ranges to drop any initial row where any feature is outside its allowed interval, and then classify new brews with 5-NN using Euclidean distance for those 3 features. If votes tie, print the alphabetically smallest label. Assume at least five rows remain after filtering.
The first line of the input contains a single integer n
representing how many labeled brews are in the initial list. The second line contains six floating-point numbers: the minimum and maximum for each feature in order: hue_min hue_max temp_min temp_max visc_min visc_max
. Each of the next n
lines contains three floating-point numbers and a label with no spaces: hue temperature viscosity label
.
The next line contains a single integer q
representing how many new brews to classify. Each of the next q
lines contains three floating-point numbers: hue temperature viscosity
- to be classified after filtering the initial list by the given ranges.
The program should print q
lines. Each line should contain the predicted label for the corresponding new brew.
Input | Output |
---|---|
10 | ELIXIR |
10 | ELIXIR |
7 | TONIC |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB