아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Freestyle Masonry

시간 제한2초메모리 제한1024 MB

요약
일부 칸이 이미 채워진 w×h 벽을 남은 2×1 벽돌만으로 정확히 완성할 수 있는지 판정한다.
난이도

보통10점 중 7점

유형
그리디, 동적 계획법, 구현, 배열
정답자
아직 제출이 없습니다

문제

Fred got a simple task, he just has to build a w×hw\times h wall. To make this even easier, he was provided with enough 2×12\times1 bricks and also a few 1×11\times1 bricks to complete the wall. Knowing that this task should not be too hard, Fred went to work and started building the wall without thinking too much about the design. Only when he ran out of 1×11\times1 bricks, Fred noticed that this might have been a bad idea...

Figure F.1: Visualization of Sample Input 22. 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).

Maybe he should have made a plan before starting to build the wall, but now it is too late. Fred only has a bunch of 2×12\times1 bricks left and wants to finish the wall. Can he still complete it with the remaining 2×12\times 1 bricks? Note that the wall to be built should have a width of exactly ww units and a height of exactly hh units.

입력

The input consists of:

  • One line with two integers ww and hh (1≤w≤2⋅1051\leq w\leq2\cdot10^5, 1≤h≤1061\leq h\leq10^6), the width and height of the wall Fred wants to build.
  • One line with ww integers h_1,…,h_nh\_1,\dots,h\_n (0≤h_i≤1060\leq h\_i\leq 10^6), where h_ih\_i is the current height of the wall at position ii.

출력

Output "possible" if Fred can complete his wall and "impossible" otherwise.

예제4

  1. 예제 1

    입력
    3 3
    0 0 1
    
    예상 출력
    possible
    
  2. 예제 2

    입력
    6 3
    1 0 1 1 0 1
    
    예상 출력
    possible
    
  3. 예제 3

    입력
    6 2
    1 0 1 1 0 1
    
    예상 출력
    impossible
    
  4. 예제 4

    입력
    5 2
    1 2 3 2 2
    
    예상 출력
    impossible