Dynamic Programming Practice 1


Submit solution


Points: 7
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
Assembly, Awk, Brain****, C, C++, Java, Pascal, Perl, Python, Sed, Text

Simon has stumbled upon an array \(a\) of \(N\) integers and wishes to find the maximal sum of the elements he can pick. One restriction exists - he cannot pick two adjacent elements.

Constraints

\(1 \leq N \leq 10^{5}\)

\(1 \leq a_{i} \leq 10^{3}\)

Input Specification

The first line contains \(N\).

The second line contains \(N\) integers, \(a_{i}\).

Output Specification

Output one integer, the maximal sum possible.

Sample Input

5
4 5 6 9 10

Sample Output

20

Explanation for Sample Output

The optimal way to pick elements would be \(4\), \(6\), and \(10\). It can be shown that a larger sum cannot be obtained.


Comments

There are no comments at the moment.