Observe that the probability of the i'th student getting a cold drink is dependent on the number of rows with a cold drink in front and the number of rows with a hot drink in front. By looking at the calculations of the probability you can see that you want to maximize #cold/#hot. Hence, you can greadily refill the fridge, starting with the rows with the most amount of available slots. If the number of reachable cold cans are below "m" when we are done, we output ``You will loose access to the soda fridge!'' instead.