## Summing A Sequence

View as PDF

Points: 7
Time limit: 0.6s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Bob is trying to solve Kirito's favourite problem, Maintaining a Sequence! He decides that he must first explore some properties of integer sequences in order to solve it. Bob has a sequence , consisting of integers. He wants to add some of the elements together to obtain the maximum sum possible. However, to make this problem more challenging, Bob decides that he will not add two consecutive elements to his total. In other words, Bob wants to find a subset of his sequence that yields the maximum sum while not containing any adjacent elements.

Note: this subset can be empty, in which case the sum is 0.

#### Input Specification

The first line contains one integer, , the number of elements in the sequence.
The second line contraints space-separated integers, , the elements of the sequence.

#### Sample Input

6
1 3 -2 5 -7 10

#### Sample Output

18

## Comments

There are no comments at the moment.