ContestCoordinator
SRM 309 · 2006-06-28 · by _efer_
Problem Statement
You are the coordinator of a contest, and you have been presented with the final scores of all the contestants. It is now your job to determine the quality of the contest. To do this, you will compute the average score after eliminating the k highest scoring contestants and the k lowest scoring contestants. k is a non-negative integer (it can be 0), and you will choose a value for k that yields the maximum average score. Return a double representing this maximum average score. You are not allowed to eliminate all the scores.
Notes
- The returned value must be accurate to 1e-9 relative or absolute.
Constraints
- scores will contain between 1 and 50 elements, inclusive.
- Each element of scores will be between 1 and 1000, inclusive.
{5,3,3,10,10,4,3,10,10,3,9,5,7,10}
Returns: 6.666666666666667
{9,5,1,7,7,7,1,5,3,10,1,5,5,3,8,10,5,7,1,6,5,9,7,7,8,10,6,9,9,1,4,5,10,6,4,2,8,5,8,7,10,4,3,2,3,10,3,9,4,3}
Returns: 5.8125
{1,4,1,1,2,10,6,4,8,6,6,3,3,9,2,2,5,3,4,9,9,10,9,4,7,7,4,10,10,9,9,6,4,5,3,10,8,9,9,9,4,5,1}
Returns: 6.0
{2,5,8,2,4,1,7,4,3,2,8,5,1,2,7,1,10}
Returns: 4.235294117647059
{8,6,7,3,1,4,5,4,5,5,10,7,1}
Returns: 5.142857142857143
{1}
Returns: 1.0
There's nothing to remove here.
{1,2,3,4}
Returns: 2.5
Eliminating the first and the last score yields an average score of 2.5
{1,1,999,999,1000,1000}
Returns: 999.0
Keep only the scores equal to 999.
Submissions are judged against all 121 archived test cases, of which 8 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ContestCoordinator with a public method double bestAverage(vector<int> scores) · 121 test cases · 2 s / 256 MB per case