atcoder#AGC046E. [AGC046E] Permutation Cover

[AGC046E] Permutation Cover

Score : 15001500 points

Problem Statement

Given are an integer KK and integers a1,,aKa_1,\dots, a_K. Determine whether a sequence PP satisfying below exists. If it exists, find the lexicographically smallest such sequence.

  • Every term in PP is an integer between 11 and KK (inclusive).
  • For each i=1,,Ki=1,\dots, K, PP contains aia_i occurrences of ii.
  • For each term in PP, there is a contiguous subsequence of length KK that contains that term and is a permutation of 1,,K1,\dots, K.

Constraints

  • 1K1001 \leq K \leq 100
  • 1ai1000(1iK)1 \leq a_i \leq 1000 \quad (1\leq i\leq K)
  • a1++aK1000a_1 + \dots + a_K\leq 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

KK

a1a_1 a2a_2 \dots aKa_K

Output

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

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

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

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