Absolute Permutation
medium⏱ 15 mintypescriptchallengesproblem-solving-intermediate-
Caso de ejemplo — tu programa lee de stdin e imprime en stdout.
Find lexicographically smallest permutation P of [1..n] where |P[i] - i| = k for all i (1-indexed), or return -1.
Algorithm: For each position i, P[i] must be either i+k or i-k. If k=0, return [1,2,...,n]. If n % (2k) ≠ 0, impossible. Otherwise, arrange in blocks: positions 1..k use i+k, positions k+1..2k use i-k, repeat.
Example: n=4, k=2 → P[1]=3, P[2]=4, P[3]=1, P[4]=2 → Check: |3-1|=2, |4-2|=2, |1-3|=2, |2-4|=2 ✓ → Output: '3 4 1 2'
Formato de entrada
First line: t (test cases). Next t lines: n k (space-separated).
Formato de salida
For each test case, output the permutation as space-separated integers, or -1 if impossible.
Restricciones
1 ≤ t ≤ 10, 1 ≤ n ≤ 10⁵, 0 ≤ k < n