#K68117. Circular Sequence Generation
Circular Sequence Generation
Circular Sequence Generation
Given two integers \( n \) and \( k \), generate a sequence \( a_1, a_2, \dots, a_n \) consisting of integers in the range \([1, k]\) such that for every pair of consecutive elements \( a_i \) and \( a_{i+1} \), the circular distance is exactly 1. In other words, if we define the circular distance between two numbers \( a \) and \( b \) as \( \min(|a-b|, k-|a-b|) \), then it must hold that
[ \min(|a_i - a_{i+1}|,; k-|a_i-a_{i+1}|) = 1 \quad \text{for } 1 \le i < n. ]
If there is no sequence that satisfies the above condition, output \(-1\). Note that when \( k = 1 \), the only valid sequence is possible if \( n = 1 \); for \( n > 1 \) no valid sequence exists.
Examples:
- For \( n = 5 \) and \( k = 3 \), one valid output is:
1 2 3 1 2
(other rotations of the sequence1 2 3
are also valid). - For \( n = 4 \) and \( k = 1 \), output \(-1\).
- For \( n = 3 \) and \( k = 2 \), one valid output is:
1 2 1
(or2 1 2
).
inputFormat
The input consists of a single line containing two space-separated integers:
- \( n \) \( (1 \le n \le 10^5) \): the length of the sequence.
- \( k \) \( (1 \le k \le 10^3) \): the maximum value allowed in the sequence.
The input is read from standard input (stdin).
outputFormat
If a valid sequence exists, output the sequence as \( n \) space-separated integers on a single line to standard output (stdout). Otherwise, output -1.
## sample5 3
1 2 3 1 2