← All problemsSign in

Generating A Permutation

For a permutation \( P = (p_1, p_2, \dots, p_N) \) of numbers \([1, 2, \dots, N]\), we define the function \( f(P) = \max(p_1, p_2) + \max(p_2, p_3) + \dots + \max(p_{N-1}, p_N) \). You are given \( N \) and an integer \( K \). Find and report a permutation \( P \) of \([1, 2, \dots, N]\) such that \( f(P) = K \), if such a permutation exists. Note \( f([1]) = 0 \). ### Input - The first line o

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