← All problemsSign in

Sorting Segments

CodeChefRating 2193Open on judge ↗

You are given a permutation $P$ of integers from $1$ to $N$, and an integer $K$ such that $\lceil \frac{2N}{3}\rceil \le K \le N$. In one operation, you can do the following: - Choose any consecutive segment of at most $K$ elements of the permutation, and sort it in increasing order. What's the smallest number of operations you have to make to sort the entire 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.

voice by Sarvam AI

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

Sign in to start