시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB38181847.368%

문제

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

1 2 4
1 2 3

예제 입력 2

14 3
3 4 1 1 1 2 3 1 2 1 1 5 6 7

예제 출력 2

6 1 3
2 4 1
5 1 2
1 3 7

예제 입력 3

8 5
1 1 2 2 3 3 4 4

예제 출력 3

impossible

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > The UK & Ireland Programming Contest > UKIEPC 2019 C번

  • 문제를 만든 사람: Robin Lee