A mountain research station manages a network of n alpine catchment reservoirs that store glacial meltwater collected over the season. Each evening, for exactly k consecutive cycles, the station's automated controller identifies whichever reservoir currently holds the most water and lets it evaporate down to floor(sqrt(volume)) liters — the thermal-loss model the station uses for its fullest reservoir each cycle. (If several reservoirs are tied for the most water, the controller may pick any one of them; the network's final total is the same no matter which tied reservoir is chosen.) After all k cycles have run, the station wants to know how much water remains across the whole network.
A single integer: the total volume, in liters, remaining across all n reservoirs after exactly k evaporation cycles.
Example 1
Input
3 2 16 25 4
Expected
13
Explanation
Cycle 1: the fullest reservoir is 25, which evaporates to floor(sqrt(25)) = 5, giving [16, 5, 4]. Cycle 2: the fullest is now 16, which evaporates to floor(sqrt(16)) = 4, giving [4, 5, 4]. The total is 4 + 5 + 4 = 13.
Example 2
Input
4 1 9 9 9 9
Expected
30
Explanation
All four reservoirs are tied at 9. The controller evaporates any one of them to floor(sqrt(9)) = 3, leaving [3, 9, 9, 9] (in some order). The total is 3 + 9 + 9 + 9 = 30.
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 →