Problem B
Fair Division
It’s your friend’s birthday, and you and some other people decided to buy him a copy of StarCraft II, because who wouldn’t want to have that?
You agreed to divide the costs as fairly as possible. Since some of you have more money available than others, you also agreed that nobody has to pay more than he can afford. Every contribution will be a multiple of 1 cent, and nobody can pay fractions of a cent.
Everybody writes down the maximum amount he is able to
contribute. Taking into account these maximum amounts from
everybody, you share the cost of the present as fairly as
possible. That means, you minimize the largest distance of the
contributions to
Since you bought the present, it is your task to figure out how much everybody has to pay (including you).
Input
On the first line a positive integer: the number of test cases, at most 100. After that per test case:
-
One line with two integers
and : the price of the present in cents and the number of people who contribute to the present (including you). -
One line with
integers , where is the maximum amount, in cents, that the -th person on the list is able to contribute.
Output
Per test case:
-
One line with
integers: the amounts each person has to contribute according to the scheme, or “IMPOSSIBLE” if the amount cannot be shared.
Sample Input 1 | Sample Output 1 |
---|---|
3 20 4 10 10 4 4 7 3 1 1 4 34 5 9 8 9 9 4 |
6 6 4 4 IMPOSSIBLE 8 7 8 7 4 |