CiscoOA #2
Tallest Chocolate Stack
Estimated MediumJudge-ready
Topics (AI-labelled)DP Basics
Jars are arranged in a line. You may choose any number of jars, but you cannot choose two adjacent jars; you take all the chocolates in the chosen jars. Find the maximum total. Empty jars are allowed, and taking nothing is also allowed. The first and last jars are not adjacent.
Input
The first line contains N, and the second line contains N non-negative chocolate counts. The OCR gives 1<N≤1000, while the complete Fastprep version of the same problem explicitly gives 1≤N≤1000; this site follows the latter so that a single jar is covered. The original has no upper bound on the count in a jar; this site adds 0≤a[i]≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
6
5 30 99 60 5 10
Output:
114
Example 2
Input:
1
9
Output:
9
Example 3
Input:
3
9 0 9
Output:
18
Example notes
The outputs of the three public examples are, in order: 114; 9; 18. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…