#C4535. Reordering List to Avoid \(i \bmod k\) Conflicts
Reordering List to Avoid \(i \bmod k\) Conflicts
Reordering List to Avoid (i \bmod k) Conflicts
You are given an integer k and a list of n integers. Your task is to reorder the list so that for every index \(i\) (0-indexed) the following condition holds:
[ a_i \neq i \bmod k ]
If such a reordering is possible, output Yes
on the first line and the valid reordered list (with elements separated by spaces) on the second line. Otherwise, output No Solution
.
Note: In this problem, if k equals 1 and the list contains more than one element, you must output No Solution
, even if the condition appears to hold.
inputFormat
The input is given from standard input and has the following format:
n k a1 a2 ... an
where n is the number of integers in the list, k is the modulus parameter, and ai
are the integers of the list.
outputFormat
If a valid reordering exists, print Yes
on the first line, and on the second line print the reordered list (the integers separated by a single space). Otherwise, print No Solution
.
5 3
1 2 3 4 5
Yes
1 2 3 4 5
</p>