K Different Values

AtCoder
IDarc128_e
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
3 3
2 2 1
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.
Input #2
3 2
2 1 2
Output #2
1 2 3 1 3
Input #3
3 3
1 3 3
Output #3
\-1
API Response (JSON)
{
  "problem": {
    "name": "K Different Values",
    "description": {
      "content": "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$ ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc128_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given are a sequence of $N$ integers $A=(A_1,A_2,\\cdots,A_N)$ and an integer $K$.\nConsider making a sequence of integers $x$ that satisfies both of the following conditions.\n\n*   For each integer $i$ ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments