Keep it Cool
Time limit2sMemory limit512 MB
Place n new sodas into s slots of capacity d, each slot already holding some cold sodas in front, to maximize the chance that the next m students all take a cold one.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics, Probability
- Solved
- No attempts yet
Problem
As the semester workload ramps up, you have to refill the lab fridge with soda. The fridge has slots, each with a capacity for bottles of soda, and you have new soda bottles to add. The sodas already in the fridge are nice and cold, but the new ones are not. They need to stay in the fridge for a while before they are ready to drink.
You can only refill the fridge from the front. In an ideal world, you would take out all the sodas currently in the fridge, put in the new ones, and then put the old cold sodas in front of the new ones. But you have two exams and a homework deadline coming up, so you do not have time for all that work.
Instead, you put the new bottles in the front of the fridge and hope for the best. You can still choose which slots receive the new sodas. Each time a student comes for a soda, they take one from the front of a uniformly random non-empty slot. You decide where to add the new bottles to maximize the probability that all of the next students get a cold one.
Input
The first line contains four integers , , , and (), the number of new soda bottles, the number of students to optimize for, the number of slots, and the capacity of each slot. The second line contains integers ( for each ), where is the number of soda bottles currently in slot .
You may assume there is free space for all new bottles in the fridge.
Output
If there is a chance that all of the next students get a cold bottle, output integers describing a refill scheme for the soda bottles that maximizes the probability of this. The -th integer is the number of new bottles placed in the front of slot . If several refill schemes are optimal, output any one of them. Otherwise, if it is impossible for all of the next students to get a cold soda, output "impossible".