The Fair Flavor Score
A food critic club rates a new dish every day. Some reviewers are generous, others are harsh - so the chef wants to ignore the extreme ratings on both ends before averaging.
You are asked to compute the k% trimmed mean - ignore a fixed percentage of the lowest ratings and the same percentage of the highest ratings, then average what’s left.

The first line of the input contains a single integer n
- the number of ratings.
The second line contains n
space-separated integers - the ratings.
The third line contains an integer p
- the percentage to trim from each end (in percent).
The program should drop the k%
smallest and the k%
largest ratings (after sorting), then print the mean of the remaining ratings. It is guaranteed that at least one rating remains after trimming.
Input | Output |
---|---|
7 | 22.8 |
10 | 18.125 |
5 | 3 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB