#P11132. Maximum Permutation Value
Maximum Permutation Value
Maximum Permutation Value
You are given two positive integers and . A permutation (p = [p_1,p_2,\dots,p_n]) of ({1,2,\dots,n}) has a value defined as the greatest common divisor (gcd) of the maximum values of every contiguous subarray of length (m). In other words, for every index (i) from (1) to (n-m+1) we define [ M_i = \max{p_i, p_{i+1}, \dots, p_{i+m-1}}, ] and the value of the permutation is [ V = \gcd{M_1, M_2, \dots, M_{n-m+1}}. ] A technical note: by convention, the gcd of a single number is the number itself.
Your task is to output any permutation of ({1,2,\dots,n}) whose value is maximum among all (1\sim n) permutations. It is guaranteed that a custom validator will check that your permutation indeed has the maximum value.
Hint: When (n) is not too large relative to (m) (more precisely, when (n\le 2m-1)), it is possible to force every contiguous subarray of length (m) to have the same maximum. For example, one may put the largest element in the intersection of all subarrays. For the general case (when (n>2m-1)) an optimal construction exists but it is more technical. For this problem a solution that treats the two cases separately is acceptable.
inputFormat
The input consists of two space‐separated integers (n) and (m) on a single line.
outputFormat
Output (n) space‐separated integers representing a permutation of ({1,2,\dots,n}) whose value (defined above) is maximum.
sample
5 3
1 2 5 3 4
</p>