A coastal monitoring authority anchors n buoys along a shoreline during a storm-watch cycle. Every buoy reports a distinct crest height, in millimeters, for the cycle. Because the network's single highest reading and single lowest reading are each treated as possible sensor glitches, the authority discards exactly one buoy with the maximum reported height and exactly one buoy with the minimum reported height, then reports the average crest height of the buoys that remain.
n, the number of buoys.n space-separated distinct integers h_1 h_2 ... h_n, the crest height reported by each buoy, in millimeters.Print a single line containing the average crest height of the remaining n - 2 buoys after discarding the one minimum and one maximum reading, rounded to exactly 5 digits after the decimal point.
Example 1
Input
4 4000 3000 1000 2000
Expected
2500.00000
Explanation
The buoy readings are 4000, 3000, 1000, and 2000 mm. The minimum reading is 1000 and the maximum is 4000, so those two buoys are discarded, leaving 3000 and 2000. Their average is (3000 + 2000) / 2 = 2500.00000.
Example 2
Input
3 1000 2000 3000
Expected
2000.00000
Explanation
The buoy readings are 1000, 2000, and 3000 mm. Discarding the minimum (1000) and the maximum (3000) leaves only 2000, so the average of the remaining buoy is simply 2000.00000.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →