← All problemsSign in

Array Division

CodeChefRating 2631Open on judge ↗

Given a sequence $X$ of length $M$, $f(X)$ is defined as $f(X) = \sum_{i = 1}^{M - 1} |X_{i + 1} - X_i|$. Specifically, if $M = 1$, then $f(X) = 0$. For e.g., $f([3, 1, 7, 2]) = |1-3| + |7-1| + |2-7| = 13$ JJ has an array $A$ of length $N$. He wants to divide the array $A$ into two subsequences $P$ and $Q$ (possibly empty) such that the value of $f(P) + f(Q)$ is as large as possible. (Note tha

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