Problem Overview
- Consider the permutation 1 to
called . - The parameters
that satisfies and are given. - Find the permutation which satisfies
. - Print any permutation of length
that fits the condition above if such a permutation exists; otherwise, -1.
Problem Explanation
First, consider the minimum and the maximum value we can generate with the length
Hereafter, we define
Minimum Value
As an arithmetic sequence with first term 1, term number
Maximum Value
As an arithmetic sequence with first term
Any number
Coding
First, we prepare the vector
Consider in descending order.
Start the for loop from
if
Iterate this until
The remaining part of the implementation is to insert the unused numbers into the empty parts of the vector.