Problem Statement
Several judges submit scores as part of a competition. It is known that some judges tend to score highly, and some tend to score lower. Therefore, the organizers of the competition came up with a specific scoring formula. This formula is described below and your task is to implement it.
Given a sequence of scores given by the judges, we will call the highest third of them (rounded down if necessary) the "high scores", the lowest third (again, rounded down if necessary) the "low scores", and all the other scores are called "middle scores". We then take an average (i.e., mean) high score, an average low score, and an average middle score. The final score is then computed as the sum of those three values.
Given the
Definition
- Class:
- ScoringJudges
- Method:
- overallScore
- Parameters:
- int[]
- Returns:
- double
- Method signature:
- double overallScore(int[] individualScores)
- (be sure your method is public)
Notes
- If multiple judges submit the same score, it is possible that different groups of scores will contain individual scores with the same value. See the Examples for further clarification.
- The return value must have an absolute or a relative error at most 1e-9.
Constraints
- individualScores will contain between 3 and 50 elements, inclusive.
- Each element of individualScores will be between 0 and 100, inclusive.
Examples
{60, 30, 20, 40, 10, 50}
Returns: 105.0
The high scores are 50 and 60, the low scores are 10 and 20, and the middle scores are 30 and 40. The average high score is (50 + 60) / 2 = 55, the average low score is 15, and the average middle score is 35. The final score is 55 + 15 + 35.
{47, 47, 47, 47, 47, 47, 47}
Returns: 141.0
All seven judges gave the same score. As 7/3 (rounded down) is 2, we take two of these as the high scores, two of them as the low scores, and the remaining three are the middle scores. Clearly, each group of scores has the mean 47, so the final score is 47 + 47 + 47.
{1, 1, 1, 3, 3, 4, 4, 4}
Returns: 7.75
The average high score is (4 + 4) / 2, the average low score is (1 + 1) / 2, and the average middle score is (1 + 3 + 3 + 4) / 4.
{87, 35, 22, 15, 33, 19}
Returns: 105.5
{87, 35, 22, 15, 33, 19, 5, 82, 11, 83, 9}
Returns: 117.13333333333333
{73,14,49,57,50,53,59,11,8,61,30,61,14,56,36,6,51,76,18,68,67,4,15,40,36,66,1,29,72,60,10,26,7,37,38,51,80,87,60,45,78,52,24,79,93,92,86,49,60,2}
Returns: 137.45833333333334
{73,14,49,57,50,53,59,11,8,61,30,61,14,56,36,6}
Returns: 118.46666666666667
{51,76,18,68,67,4,15,40,36,66,1,29,72,60,10,26}
Returns: 119.73333333333333
{7,37,38,51,80,87,60,45,78,52,24,79,93,92,86,49,60,2}
Returns: 170.0
{79,38,0,2,21,11,41,29,6,0,33,17,93,79,7,86,22,97,34,61,98,100,24,43,70,20,67,94,10,51,43,38,40,42,45,33,14,40,34,40,36,89,83,33,88,91,85,44,95,74}
Returns: 145.90277777777777
{40,76,96,29,71,57,40,69,66,74,45,97,33,52,71,19,96,100,82,98,19,41,54,25,10,50,28,72,94,57,84,58,31,59,54,84,18,52,97,54,80,79,30,11,95,26,27,99,98,13}
Returns: 174.54166666666666
{40,35,11,90,26,21,42,19,49,11,86,90,74,75,5,11,90,83,83,4,72,8,62,68,32,1,47,53,45,46,43,58,3,74,15,99,46,49,72,36,70,70,48,46,75,34,0,54,76,46}
Returns: 143.46527777777777
{24,9,70,29,90,40,20,6,31,81,95,75,65,3,81,37,80,44,87,55,96,41,59,85,23,10,43,10,11,27,58,83,77,21,85,24,69,78,92,1,8,27,47,75,9,54,88,53,79,24}
Returns: 148.70833333333334
{30,69,37,68,16,62,7,38,3,33,6,77,79,13,58,67,39,58,99,39,33,87,68,95,35,31,62,52,66,5,61,1,80,79,7,39,59,23,21,18,59,49,17,14,14,100,35,51,28,71}
Returns: 135.52777777777777
{5, 55, 21, 70, 31, 89, 12, 100, 70, 74, 62, 89, 94, 52, 33, 95, 77, 71, 37, 64, 67, 14, 75, 33, 19, 55, 33, 61, 57, 18, 61, 74, 44, 66, 33, 65, 41, 20, 39, 26, 15, 93, 91, 97, 87, 33, 60, 11, 18, 0 }
Returns: 156.32638888888889
{1, 2, 4, 8 }
Returns: 12.0
{1, 1, 1 }
Returns: 3.0
{2, 2, 3, 3, 3, 4, 5, 5, 10 }
Returns: 12.333333333333334
{0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 3, 24, 47, 72, 2, 31, 62, 95, 33, 70, 12, 53, 96, 44, 91, 43, 94, 50, 8, 65, 27, 88, 54, 22, 89, 61, 35, 11, 86, 66, 48, 32, 18, 6, 93, 85, 79, 75, 73, 73 }
Returns: 144.0
{4, 3, 2, 1, 5 }
Returns: 9.0
{1, 2, 3, 4, 5 }
Returns: 9.0
{1, 2, 3, 4, 5, 6, 7, 8, 9, 9 }
Returns: 16.166666666666664
{60, 30, 20, 40, 10, 50 }
Returns: 105.0
{1, 2, 1, 1 }
Returns: 4.0
{1, 1, 1, 3, 3, 4, 4, 4 }
Returns: 7.75
{4, 1, 1, 1, 3, 3, 4, 4 }
Returns: 7.75
{5, 5, 6, 7, 8, 6, 6, 6 }
Returns: 18.5
{2, 2, 2 }
Returns: 6.0
{1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 10, 12, 23, 12, 9, 1, 23, 3, 4, 3, 4, 5, 4, 35, 3 }
Returns: 25.35
{1, 1, 1, 4, 4, 4, 3, 3 }
Returns: 7.75
{2, 3, 4, 1, 5 }
Returns: 9.0
{1, 2, 31, 40, 50, 60, 70, 80, 90, 90, 90 }
Returns: 161.33333333333331
{1, 6, 4, 1 }
Returns: 9.5
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Returns: 16.5
{1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 1, 1, 1, 1, 2 }
Returns: 11.8
{1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 100, 100 }
Returns: 33.714285714285715
{1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3 }
Returns: 6.6
{0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }
Returns: 0.6666666666666666
{23, 22, 54, 67, 69, 88, 76, 5, 4, 34, 69, 89, 99 }
Returns: 160.1
{1, 2, 5, 4, 1 }
Returns: 8.333333333333334