#C12298. Maximum Non-Consecutive Sum

    ID: 41709 Type: Default 1000ms 256MiB

Maximum Non-Consecutive Sum

Maximum Non-Consecutive Sum

This problem requires you to compute the maximum sum obtainable from a list of integers by selecting a subset of numbers such that no two numbers selected are adjacent in the original list. In other words, if you choose an element, you cannot choose its immediate neighbors. Note that if all numbers are negative, the best sum is defined as 0 (choosing no elements).

The solution should read input from standard input (stdin) and output the result to standard output (stdout). The input begins with an integer n which represents the number of elements, followed by n space-separated integers. The output is a single integer representing the maximum non-consecutive sum.

Note: Use a dynamic programming approach to achieve an optimal solution.

inputFormat

The first line contains an integer n, the number of elements in the array. The second line contains n space-separated integers representing the elements of the array.

outputFormat

Output a single integer which is the maximum sum that can be obtained by summing non-consecutive elements of the array.

## sample
0
0