← All problemsSign in

Permutation Cost Sum

CodeChefRating 2078Open on judge ↗

You are given a permutation $P$ of length $N$. Assume you can perform two types of operations: - Modify $P_i$ $(1 \le i \le N)$ to any number at a cost of $A$. - Swap $P_i$ and $P_j$ $(1 \le i,j \le N$, $i \neq j)$ at a cost of $B$. We define $f(P, A, B)$ as the minimum cost to make the permutation satisfy $P_i = i$ for all $i$. Your task is to calculate: $$ \sum_{1 \leq i, j \leq N} f(P, i,

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.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start