E - Permutation Cover Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 1500

問題文

整数 K と整数 a_1,\dots, a_K が与えられます。以下を満たす数列 P が存在するか判定し、存在する場合は辞書順最小のものを求めてください。

  • P のすべての項は 1 以上 K 以下の整数である
  • i=1,\dots, K に対し、Pia_i 個含む
  • P の各項について、その項を含むある長さ K の連続する部分列が存在し、1,\dots, K の並び替えになっている

制約

  • 1 \leq K \leq 100
  • 1 \leq a_i \leq 1000 \quad (1\leq i\leq K)
  • a_1 + \dots + a_K\leq 1000
  • 入力はすべて整数である

入力

入力は以下の形式で標準入力から与えられる。

K
a_1 a_2 \dots a_K

出力

条件を満たす数列が存在しない場合、-1 を出力せよ。 そうでない場合、条件を満たす辞書順最小の数列を出力せよ。


入力例 1

3
2 4 3

出力例 1

2 1 3 2 2 3 1 2 3 

例えば、5 項目の 2 は、5,6,7 項目からなる部分列 (2,3,1) に含まれます。


入力例 2

4
3 2 3 2

出力例 2

1 2 3 4 1 3 1 2 4 3 

入力例 3

5
3 1 4 1 5

出力例 3

-1

Score : 1500 points

Problem Statement

Given are an integer K and integers a_1,\dots, a_K. Determine whether a sequence P satisfying below exists. If it exists, find the lexicographically smallest such sequence.

  • Every term in P is an integer between 1 and K (inclusive).
  • For each i=1,\dots, K, P contains a_i occurrences of i.
  • For each term in P, there is a contiguous subsequence of length K that contains that term and is a permutation of 1,\dots, K.

Constraints

  • 1 \leq K \leq 100
  • 1 \leq a_i \leq 1000 \quad (1\leq i\leq K)
  • a_1 + \dots + a_K\leq 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

K
a_1 a_2 \dots a_K

Output

If there is no sequence satisfying the conditions, print -1. Otherwise, print the lexicographically smallest sequence satisfying the conditions.


Sample Input 1

3
2 4 3

Sample Output 1

2 1 3 2 2 3 1 2 3 

For example, the fifth term, which is 2, is in the subsequence (2, 3, 1) composed of the fifth, sixth, and seventh terms.


Sample Input 2

4
3 2 3 2

Sample Output 2

1 2 3 4 1 3 1 2 4 3 

Sample Input 3

5
3 1 4 1 5

Sample Output 3

-1