LIS ∩ LDS

AtCoder
IDarc206_d
Time2000ms
Memory256MB
Difficulty
Among the elements of a permutation $P=(P_1,\ldots,P_N)$ of $(1,\ldots,N)$, those that satisfy the following condition are called good elements: * The element can be included in both a longest increasing subsequence and a longest decreasing subsequence of $P$. You are given integers $N$ and $K$. Determine whether there exists a permutation $P$ of $(1,\ldots,N)$ such that there are exactly $K$ good elements, and if it exists, find one. Answer for $T$ test cases. ## Constraints * All input values are integers * $1 \leq T \leq 2\times 10^5$ * $1 \leq N \leq 2\times 10^5$ * $0\leq K \leq N$ * The sum of $N$ over all test cases does not exceed $2\times 10^5$. ## Input The input is given from Standard Input in the following format: $T$ $\mathrm{case}_1$ $\vdots$ $\mathrm{case}_T$ Each test case is given in the following format: $N$ $K$ [samples]
Samples
Input #1
3
1 0
7 2
2 1
Output #1
\-1
7 4 6 2 3 1 5
-1

In the $2$\-nd test case, $P_4=2$ and $P_5=3$ are good elements.
Indeed, $(2,3,5)$ is a longest increasing subsequence of $P$. Also, $(7,6,2,1)$ and $(7, 6, 3, 1)$ are longest decreasing subsequences of $P$.
Therefore, in this sample output, $2$ and $3$ are good elements. The other elements are not good elements, so this output satisfies the condition.
In the $1$\-st and $3$\-rd test cases, there does not exist a permutation satisfying the condition. Thus, output `-1`.
API Response (JSON)
{
  "problem": {
    "name": "LIS ∩ LDS",
    "description": {
      "content": "Among the elements of a permutation $P=(P_1,\\ldots,P_N)$ of $(1,\\ldots,N)$, those that satisfy the following condition are called good elements: *   The element can be included in both a longest incr",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc206_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Among the elements of a permutation $P=(P_1,\\ldots,P_N)$ of $(1,\\ldots,N)$, those that satisfy the following condition are called good elements:\n\n*   The element can be included in both a longest incr...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments