Under construction

Still being built. Things may change

Keep it Cool

Time limit2sMemory limit512 MB

Summary
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 ss slots, each with a capacity for dd bottles of soda, and you have nn 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 nn 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 mm students get a cold one.

Input

The first line contains four integers nn, mm, ss, and dd (1≤n,m,s,d≤1001 \le n, m, s, d \le 100), 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 ss integers c1,…,csc_1, \ldots, c_s (0≤ci≤d0 \le c_i \le d for each ii), where cic_i is the number of soda bottles currently in slot ii.

You may assume there is free space for all nn new bottles in the fridge.

Output

If there is a chance that all of the next mm students get a cold bottle, output ss integers describing a refill scheme for the nn soda bottles that maximizes the probability of this. The ii-th integer is the number of new bottles placed in the front of slot ii. If several refill schemes are optimal, output any one of them. Otherwise, if it is impossible for all of the next mm students to get a cold soda, output "impossible".

Examples2

  1. Example 1

    Input
    5 3 3 4
    0 1 4
    
    Expected output
    2 3 0
    
  2. Example 2

    Input
    2 7 6 4
    0 1 2 2 0 1
    
    Expected output
    impossible