Official algorithmic problem description and constraints.
Fox loves permutations! She came up with the following problem and asked Cat to solve it:
You are given an even positive integer π and a permutationβ π of length π.
The score of another permutation π of length π is the number of local maximums in the array π of length π, where ππ=ππ+ππ for all π (1β€πβ€π). In other words, the score of π is the number of π such that 1<π<π (note the strict inequalities), ππβ1<ππ, and ππ>ππ+1 (once again, note the strict inequalities).
Find the permutation π that achieves the maximum score for given π and π. If there exist multiple such permutations, you can pick any of them.
A permutation of length π is an array consisting of π distinct integers from 1 to π in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (π=3 but there is 4 in the array).
Detailed video explanations, mathematical intuition, and clean C++ implementation code.