Hide

Problem C
Donut Toppings

/problems/donuttoppings/file/statement/en/img-0001.jpg
Image by anya1 from Pixabay

You own a small donut company. You have $n$ donut boxes of varying sizes and $t$ different toppings that you can put on the donuts in the boxes. You are also given the number of donuts each box holds. You will apply one topping to each donut such that the number of donuts with a certain topping in each box will be within one of another box. In other words, the difference between the number of donuts with any one topping in one box and the number of donuts with the same topping in any other box is at most $1$. Other than that, you may use any topping as often or as little as you like.

Input

The input consists of two lines. The first line contains two integers $n$ ($0 < n \leq 1\, 000$) and $t$ ($0 < t \leq 1\, 000$), where $n$ is the number of boxes and $t$ is the number of toppings. The second line contains $n$ integers $d_ i$ ($0 < d_ i \leq 600$) separated by spaces, which denote the number of donuts in each box.

Output

If it isn’t possible to achieve the desired distribution of toppings, output ‘IMPOSSIBLE’. Otherwise, output $n$ lines. On the $i^{\text {th}}$ line output $d_ i$ integers that describe which toppings go on the donuts in box $i$. Donut toppings are numbered from $1$ to $t$, inclusive. If there are multiple solutions, then any of them will be accepted.

Sample Input 1 Sample Output 1
5 2
3 2 4 1 3
IMPOSSIBLE
Sample Input 2 Sample Output 2
4 4
1 2 3 4
1
1 4
1 2 4
1 2 3 4

Please log in to submit a solution to this problem

Log in