← All problemsSign in

Sort Perm

CodeChefRating 2466Open on judge ↗

We call a permutation$^{\dag}$ $P$ of length $N$ as $K$-sortable if it is possible to **sort** the permutation (in non-decreasing order) using the following operation **at most** once : - Choose a [subset](https://en.wikipedia.org/wiki/Subset) of indices from $[1, N]$; - Add $K$ to the elements present at all those indices in $P$. Given $N$ and a permutation $P$ of length $N$, find the **sum**

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