Freestyle Masonry
InterviewTime limit2sMemory limit1024 MB
Given the current column heights of a w by h wall, decide whether the empty cells can be filled exactly with 2x1 bricks.
- Level
Medium6 of 10
- Topics
- Sorting, Array, Implementation
- Solved
- No attempts yet
Problem
Fred got a simple task. He just has to build a wall. To make this easier, he was given enough bricks and a few bricks to complete the wall. Fred did not think this task would be hard, so he started building the wall without planning the design. He only noticed the problem when he ran out of bricks.

Figure F.1: Visualization of Sample Input 2. The red bricks have already been placed by Fred. The blue bricks still need to be placed to complete the wall (the only possible design in this case).
Fred has only bricks left, and he wants to finish the wall with them. Can he still complete the wall using only the remaining bricks? The wall must have a width of exactly units and a height of exactly units.
Input
The first line contains two integers and (, ), the width and height of the wall Fred wants to build.
The second line contains integers (), where is the current height of the wall at position .
Output
Output possible if Fred can complete the wall, and impossible otherwise.