## DMOPC '18 Contest 4 P6 - Dr. Henri and Resistor Chains

View as PDF

Points: 20 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Dr. Henri is trying to create a particular circuit. This circuit forms the edges of an by grid of cells so that a resistor lies across each edge of the grid, except for the rightmost edge which is a power source. For example, when , the schematic is:

He already has his power source ready. Now, he must construct the rest of the circuit.

Dr. Henri uses resistor chains. A resistor chain of length is a chain of resistors. A chain of length is simply a single resistor. He can bend a chain between its resistors, but he cannot split a chain. Dr. Henri has resistor chains of length and would like to use all of them in his circuit, so that there are no overlaps. For example, if and the lengths are , he can construct his circuit like so:

Can you help Dr. Henri build his circuit?

for all

#### Input Specification

The first line contains two space-separated integers, and .
The next line contains space-separated integers, .

#### Output Specification

On a single line, output yes if Dr. Henri can build it given his chains and no otherwise.
If he can build it, output 3 following lines, each with integers. The first line represents the top row of edges in the circuit, the second line represents the middle row (not including the power source), and the third line represents the bottom row. The integer denotes which chain is being used for that edge. The chains are labelled based on their order in the input (from to ).

#### Sample Input 1

2 3
4 1 1

#### Sample Output 1

yes
1 2
1 1
1 3

#### Sample Input 2

2 4
4 1 1 1

#### Sample Output 2

no

#### Explanation for Sample 2

Dr. Henri can make his circuit with the first three chains, but he wants to use all four.

#### Sample Input 3

3 4
3 2 3 1

#### Sample Output 3

yes
1 1 3
1 2 3
2 3 4