← All problemsSign in

Sorting with Set

CodeChefRating 2621Open on judge ↗

For a permutation $P$, define $f(P, K)$ in the following way: - Start with an empty set of pairs $S$. - You can do the following action repeatedly as many times as you want: - Choose $2$ integers $1 \le u < v \le N$ - Swap $P_u$ and $P_v$ - Add $(u, v)$ to our set $S$ - When $P$ is sorted, we define the $score$ to be $\sum(u + v + K)$ for distinct $(u, v)$ in the set $S$ - $f(P)$

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