Max Sum Decreasing Subsequence 3A012D
1. **Problem Statement:** We want to find the maximum sum of a decreasing subsequence ending at each index $i$ in an array $A$ of distinct positive integers.
2. **Definition:** Let $L[i]$ be the maximum sum of a decreasing subsequence that ends exactly at index $i$.
3. **Key Insight:** For $L[i]$, we consider all indices $j$ where $1 \le j < i$ and $A[j] > A[i]$ (because the subsequence must be strictly decreasing).
4. **Recursive Formula:** We add $A[i]$ to the maximum $L[j]$ for all such $j$ to extend the subsequence ending at $j$ by $A[i]$.
5. **Base Case:** If no such $j$ exists (no previous element greater than $A[i]$), then $L[i] = A[i]$ because the subsequence consists only of $A[i]$.
6. **Final Recursive Formula:**
$$
L[i] = A[i] + \max_{1 \le j < i, A[j] > A[i]} L[j], \quad \text{if such } j \text{ exists}
$$
$$
L[i] = A[i], \quad \text{if no such } j \text{ exists}
$$
7. **Explanation:** This formula ensures that for each position $i$, we find the best decreasing subsequence ending at $i$ by extending the best subsequence ending at some $j$ where $A[j] > A[i]$.
8. **Matching the options:** This matches option (g):
$L[i] = A[i] + \max_j L[j]$ where $1 \le j < i$ and $A[i] < A[j]$, and $L[i] = A[i]$ if no such $j$ exists.
**Note:** The condition $A[i] < A[j]$ is equivalent to $A[j] > A[i]$, which is the decreasing condition.
**Answer:** Option (g)