logo AlgoBeat OnlineJudge
登录 注册

#209967. [USACO24OPEN] Farmer John's Favorite Permutation B

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Farmer John has a permutation of length (, containing each positive integer from to exactly once. However, Farmer Nhoj has broken into FJ's barn and disassembled . To not be too cruel, FN has written some hints that will help FJ reconstruct . While there is more than one element remaining in , FN does the following:

Let the remaining elements of be ,

  • If , he writes down and removes from the permutation.
  • Otherwise, he writes down and removes from the permutation.

At the end, Farmer Nhoj will have written down integers , in that order. Given , Farmer John wants to enlist your help to reconstruct the lexicographically minimum consistent with Farmer Nhoj's hints, or determine that Farmer Nhoj must have made a mistake. Recall that if you are given two permutations and , is lexicographically smaller than if at the first position where the two differ.

输入格式

Each input consists of independent test cases (). Each test case is described as follows:

The first line contains .

The second line contains integers ().

输出格式

Output lines, one for each test case.

If there is a permutation of consistent with , output the lexicographically smallest such . If no such exists, output .

样例

样例输入 1

5
2
1
2
2
4
1 1 1
4
2 1 1
4
3 2 1

样例输出 1

1 2
-1
-1
3 1 2 4
1 2 3 4

数据范围与提示

For the fourth test case, if then FN will have written down .

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 would also produce the same , but is lexiocgraphically smaller.

For the second test case, there is no consistent with ; both and would produce , not .

SCORING:

  • Input 2:
  • Inputs 3-6:
  • Inputs 7-11: No additional constraints.