Ascents and Descents
For a permutation $P$ of the integers $[1, N]$, let $Q$ be the unique inverse permutation of $P$ (i.e. $Q_{P_i} = i$). Define $f(P) = \sum_{i = 1}^{N - 1}[P_i < P_{i + 1}] + \sum_{i = 1}^{N - 1}[Q_i > Q_{i + 1}]$, where $[X]$ is $1$ if $X$ is true, $0$ otherwise. In other words, $f(P)$ is the sum of number of ascents in $P$ and descents in $Q$. --- Given $N$ and $K$, your task is to find a pe
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.
Sign in to chat with the tutor and save your progress.
Sign in to start