Non-Adjacent Maximum Sum
Pick some elements so that no two picked elements are next to each other, maximising their sum. All values are non-negative.
Input
, then integers.
Output
The maximum sum.
Constraints
,
Sample 1
Input
4 1 2 3 1
Output
4
Sample 2
Input
5 2 7 9 3 1
Output
12