PivotOJ

Crooked Dealing

시간 제한: 2000ms메모리 제한: 512MB출처: UKIEPC 2019BOJ 17796

문제

This week you started a flashy new job in Leeds as a poker dealer. Your task will be to hand out the cards for games. The base pay is not particularly good, but you found out that you can earn a lot from tips if you deal the cards well.

The most generous customers prefer that their opponents at the table don’t receive any pairs of cards with the same number; so to keep them happy you will make sure this never happens.

You already know the numbers on every card in the pile , and the number of cards any player must have in their hand. Find how many hands you can make at once without introducing a pair.

Figure C.1: Illustration of a solution to Sample Input 2.

입력

The input consists of:

  • A line with two integers n and h (1 ≤ h ≤ n ≤ 106), the number of cards in the pile, and the number of cards in a hand.
  • A line with n integers v1, . . . , vn (1 ≤ vi ≤ 106 for all i), the numbers on the cards in no particular order.

출력

If it is not possible to make any hands at all without introducing a pair, output impossible.

Otherwise, output k lines (where k is the maximum possible number of players) each containing h numbers from the input. You may not use any number any more times than it appears in v.

If there are multiple answers with a maximum value of k, you may output any one of them.

예제

예제 1

입력
6 3
1 2 1 2 3 4
출력
1 2 4
1 2 3

예제 2

입력
14 3
3 4 1 1 1 2 3 1 2 1 1 5 6 7
출력
6 1 3
2 4 1
5 1 2
1 3 7

예제 3

입력
8 5
1 1 2 2 3 3 4 4
출력
impossible
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.