The Outlier Guard
Your team runs a public scoreboard for a daily guessing game. Most guesses are reasonable, but a few wild ones can throw things off. To keep the board fair, you “cap” every new guess to stay close to a typical value learned from past data.
You are asked to learn the median from yesterday’s scores, then clamp each new score so it stays within a band of size T
around that median.

The first line of the input contains a single integer n
- the number of scores from yesterday. The second line contains n
space-separated numbers - the scores from yesterday.
The third line contains a number T
- the allowed distance from the median.
The fourth line contains an integer q
- the number of new scores you need to normalize today. The next q
lines contain the new scores to clamp.
Compute the median from yesterday (if n
is odd, it’s the middle value after sorting; if n
is even, it’s the average of the two middle values).
After that, normalize the q
values to make sure each of those is within the median ± T
range and print them.
Input | Output |
---|---|
5 | 13.5 |
4 | 6 |
6 | 1.3 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB