#P13701. [NWERC 2023] Brickwork

[NWERC 2023] Brickwork

题目描述

Bob the Builder is tired of building tiny houses and paving narrow roads, and he strives for something bigger. The new job given to him by a very eccentric client is exactly what he needs: He is tasked with building a wall of a certain width that is infinitely high! His client assured him that he does not need to worry about the building material, and that an infinite supply of various kinds of bricks has already been ordered for him. Of course, building a stable wall takes very careful planning, especially if it is supposed to be infinitely high. In particular, a wall is only stable if no two gaps between bricks in consecutive rows end up directly above each other, as shown in Figure B.1. Bob knows from his long-time experience that if it is possible to build such a wall, then it can be done by alternating just two row configurations.

:::align{center} Figure B.1: On the left, we see an unstable wall using the brick types of Sample Input 1. On the right, we see a stable wall using the same brick types. Note that even though only two rows of the wall are shown, it is possible to build an infinitely high wall by repeating these two row configurations. :::

Bob is terribly excited about the new job and quickly goes to work. Given the types of bricks available, is it possible to build a stable wall of width exactly ww and infinite height? If yes, how should Bob build it using only two alternating row configurations?

输入格式

The input consists of:

  • One line with two integers nn and ww (1n,w3105)(1\leq n,w\leq3\cdot10^5), the number of brick types and the width of the wall.
  • One line with nn integers bb (1bw1\leq b\leq w), the widths of the brick types.

Note that Bob has an infinite supply of all brick types.

输出格式

If it is possible to build a wall, then output "possible\texttt{possible}". Otherwise, output "impossible\texttt{impossible}".

If a wall can be built, provide two row configurations that can be used in an alternating fashion. For both rows, first output the number of bricks needed for that row, followed by the lengths of the bricks in the order you want to use them. Your solution is considered valid if alternating the two rows infinitely would result in a stable wall.

If there are multiple valid solutions, you may output any one of them.

4 12
3 2 7 2
possible
5
2 2 3 2 3
3
3 2 7
3 11
6 7 8
impossible