Trimmed and Corrected Mean
InterviewTime limit1sMemory limit256 MB
Given N judge scores and an integer K, sort the scores, then output the trimmed mean that drops K from each end and the corrected mean that replaces those extremes with the nearest kept value, both rounded to two decimals.
- Level
Easy3 of 10
- Topics
- Sorting, Prefix sum, Math, Implementation
- Solved
- No attempts yet
Problem
In sports such as gymnastics or diving, some judges sometimes give an unfairly high score to an athlete they like and an unfairly low score to one they dislike. Taking a plain average of all such scores can therefore be unfair. To prevent this, a trimmed mean and a corrected mean (a Winsorized mean) are used instead.
For example, suppose seven judges gave the following scores.
9.3, 9.5, 9.6, 9.8, 9.1, 5.0, 9.3
Their sum is 61.6, so the plain average is 8.8. This value is dragged down by the single unusually low score of 5.0, and the athlete would feel it is very unfair.
Sorting the scores from smallest to largest gives the following.
5.0, 9.1, 9.3, 9.3, 9.5, 9.6, 9.8
- Trimmed mean : from the sorted scores, discard values from each end and average the remaining values. In the example above, the trimmed mean drops two values from each end and averages 9.3, 9.3, 9.5, giving 9.37.
- Corrected mean : instead of discarding the values at each end, replace them with the nearest kept value. That is, the smallest scores are each replaced by the -th smallest score and the largest scores by the -th largest score, and then all values are averaged. In the example above, the corrected mean averages 9.3, 9.3, 9.3, 9.3, 9.5, 9.5, 9.5, giving 9.39.
Given scores and the count removed (or replaced) at each end, write a program that computes the trimmed mean and the corrected mean .
Input
The first line contains the total number of scores and the number removed from each end, separated by a space. is a natural number with , and is an integer with .
Each of the next lines contains one judge's score. Each score is a real number between 0.0 and 10.0 inclusive, given to one decimal place.
Output
Print the trimmed mean on the first line and the corrected mean on the second line. Round each value half up at the third decimal place and print it to two decimal places.
For example, print 9.667 as 9.67, 5 as 5.00, and 5.5 as 5.50.