201284: [AtCoder]ARC128 E - K Different Values

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $800$ points

Problem Statement

Given are a sequence of $N$ integers $A=(A_1,A_2,\cdots,A_N)$ and an integer $K$.

Consider making a sequence of integers $x$ that satisfies both of the following conditions.

  • For each integer $i$ ($1 \leq i \leq N$), $x$ contains exactly $A_i$ occurrences of $i$. $x$ does not contain other integers.
  • For every way of choosing $K$ consecutive elements from $x$, their values are all distinct.

Determine whether it is possible to make $x$ that satisfies the conditions. If it is possible, find the lexicographically smallest such $x$.

Constraints

  • $2 \leq K \leq N \leq 500$
  • $1 \leq A_i$
  • $\sum_{1 \leq i \leq N} A_i \leq 200000$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $K$
$A_1$ $A_2$ $\cdots$ $A_N$

Output

If it is impossible to make a sequence $x$ that satisfies the conditions, print -1. If it is possible, print the lexicographically smallest such $x$.


Sample Input 1

3 3
2 2 1

Sample Output 1

1 2 3 1 2

Two sequences $x=(1,2,3,1,2),(2,1,3,2,1)$ satisfy the conditions. The lexicographically smaller one, $(1,2,3,1,2)$, is the answer.


Sample Input 2

3 2
2 1 2

Sample Output 2

1 2 3 1 3

Sample Input 3

3 3
1 3 3

Sample Output 3

-1

Input

题意翻译

给你一个长度为 $n$ 的整数序列 $A$ 以及一个整数 $k$ ,请你构造一个序列 $B$,满足以下两个条件 : - 值为 $i$ 的数出现了 $A_i$ 次; - 对于 $1 \leq i \leq n-k+1$ , 满足 $B_i \neq B_{i+1} \neq B_{i+2} \neq \cdots \neq B_{i+k-1}$。 如果无解,输出 $-1$;否则输出你能构造出的字典序最小的序列 $B$。

加入题单

上一题 下一题 算法标签: