← All problemsSign in

Not-too-far Replacement

CodeChefRating 1336Open on judge ↗

You are given an array $A$ of length $N+1$, denoted $[A_1, A_2,\ldots, A_{N+1}]$. You can perform the following operation on the array $A$: - Choose an index $i$ ($1 \leq i \leq N$) such that $A_i \leq 2\cdot A_{N+1}$. Then, swap the values of $A_i$ and $A_{N+1}$. That is, you can swap the element at index $N+1$ with some element of the array that's *at most* twice as large as it. You may per

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