문제
Farmer John has a permutation
Let the remaining elements of
If
p'_1 > p'_n , he writes downp'_2 and removesp'_1 from the permutation.Otherwise, he writes down
p'_{n-1} and removesp'_n from the permutation.
At the end, Farmer Nhoj will have written down , in that order. Given h_1, h_2, \dots, h_{N-1}
입력
Each input consists of
The first line contains
The second line contains
출력
Output
If there is a permutation
부분문제
| 번호 | 점수 | 조건 |
|---|---|---|
| #1 | 20점 | |
| #2 | 30점 | |
| #3 | 50점 | 추가 제약 조건 없음 |
예제
5
2
1
2
2
4
1 1 1
4
2 1 1
4
3 2 1
1 2
-1
-1
3 1 2 4
1 2 3 4
For the fourth test case, if
p' = [3,1,2,4]
p_1' < p_n' -> h_1 = 2
p' = [3,1,2]
p_1' > p_n' -> h_2 = 1
p' = [1,2]
p_1' < p_n' -> h_3 = 1
p' = [1]
Note that the permutation
For the second test case, there is no