266. Max Sum without Three Consecutive
MediumDynamic Programming
Pick elements so that no three consecutive elements are all picked. Print the maximum sum of picked elements (values are non-negative).
Input format
Line 1: n Line 2: n non-negative integers
Output format
The maximum sum.
Example 1
Input
5 3000 2000 1000 3 10
Output
5013
Example 2
Input
3 1 2 3
Output
5
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…