Permutation Cover

AtCoder
IDagc046_e
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
3
2 4 3
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.
Input #2
4
3 2 3 2
Output #2
1 2 3 4 1 3 1 2 4 3
Input #3
5
3 1 4 1 5
Output #3
\-1
API Response (JSON)
{
  "problem": {
    "name": "Permutation Cover",
    "description": {
      "content": "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",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc046_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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.\n\n*   Every term in $P...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments