#K83687. Maximum Non-Adjacent Sum

    ID: 36253 Type: Default 1000ms 256MiB

Maximum Non-Adjacent Sum

Maximum Non-Adjacent Sum

Given a list of integers, determine the maximum sum you can obtain by selecting a subset of non-adjacent numbers from the list. More formally, let \(a_1, a_2, \ldots, a_n\) be the sequence of integers. You are to choose a subset of these integers such that no two chosen numbers are adjacent in the original list. The goal is to maximize the sum of the selected numbers. Note that if all numbers are negative, the maximum sum is defined as 0.

Example:

Input: [3, 2, 5, 10, 7]
Output: 15

In this case, selecting 3, 5, and 7 gives you 15, which is the maximum obtainable without picking adjacent numbers.

inputFormat

The input is given via standard input (stdin) and consists of:

  1. An integer \(n\) on the first line representing the number of elements in the list.
  2. A second line containing \(n\) space-separated integers.

\(n\) \( (1 \leq n \leq 10^5)\) and the integers can be any valid integers.

outputFormat

Your program should output a single integer to standard output (stdout) representing the maximum sum obtainable by selecting non-adjacent numbers from the list.

## sample
5
3 2 5 10 7
15