#C8010. Maximum Non-Adjacent Subsequence Sum
Maximum Non-Adjacent Subsequence Sum
Maximum Non-Adjacent Subsequence Sum
Given a sequence of integers, determine the maximum sum that can be obtained by choosing a subsequence such that no two chosen elements are adjacent in the original sequence. In other words, if you select an element at index i, you cannot select elements at index i-1 or i+1. Note that if all numbers are negative, the answer should be 0 (by choosing an empty subsequence).
The problem can be mathematically formulated as follows:
Consider the following examples:
- Input: [3, 2, 5, 10, 7] → Output: 15
- Input: [-1, -2, -3] → Output: 0
- Input: [5] → Output: 5
5
3 2 5 10 7
15
$$