← All problemsSign in

Partition and Maximize

CodeChefRating 3000Open on judge ↗

You are given an array $A$ of size $N$. Consider the following steps: - Choose an integer $k$ $(1 \leq k \leq N)$; - Divide the range $[1, N]$ into $k$ intervals $[l_i,r_i]$ $(1 \leq i \le k)$ such that: - $l_1=1$ and $r_k=N$; - $l_{i+1}=r_i+1$ for all $(1 \leq i \lt k)$. - The score of this split is defined as $k-\sum_{i=1}^k \max(A_{l_i},A_{l_{i}+1},\ldots,A_{r_i})$. Find the **maximum

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