Sort Permutation
You are given a permutation $P$ of length $N$. You can perform the following operation on $P$: - Select two **distinct** indices $i$ and $j$ $(1\le i, j \le N)$ and **swap** the elements $P_i$ and $P_j$. - The cost of the operation is $abs(i-j)$. The total cost is defined as the sum of costs of all operations performed. Find the **minimum total cost** to sort the permutation in increasing order
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start