#C10763. Maximum Non-Consecutive Sum
Maximum Non-Consecutive Sum
Maximum Non-Consecutive Sum
You are given a sequence of integers representing the execution times of methods. Your task is to find the maximum sum of a subsequence such that no two consecutive elements are taken. In other words, you cannot take two adjacent numbers from the list. Formally, given an array \(a_1, a_2, \ldots, a_n\), choose a subset of indices \(i_1, i_2, \ldots, i_k\) such that no two consecutive indices are chosen and maximize the sum \(a_{i_1} + a_{i_2} + \cdots + a_{i_k}\).
Note: When \(n = 0\), there are no elements to choose from, so the result is 0.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\) which represents the number of elements in the list.
- The second line contains \(n\) space-separated integers representing the values of the list. If \(n = 0\), the second line may be empty.
outputFormat
Output a single integer representing the maximum sum that can be obtained by picking non-consecutive elements from the list.
## sample5
3 2 7 10 12
22