There is a set of N
jars containing chocolates. Some of them may be empty. Determine the maximum number of chocolates Andrew can pick from the jars given that he cannot pick from jars next to each other.
Write an algorithm to find the maximum number of chocolates that can be picked from the jars in such a way that the chocolates are not picked from jars next to each other.
Input
The first line of input consists of an integer- numJars
, representing the number of jars (N
).
The next line consists of N
space-separated integers representing the number of chocolates in each jar.
Output
Print the maximum number of chocolates that can be picked from the jars in such a way that the chocolates are not picked from jars next to each other.
Constraints
1 ≤ N
≤ 1000
💐 spike carries! ༊·°🌺
Example 1:
Input: jars = [5, 30, 99, 60, 5, 10]
Output: 114
Explanation:Andrew picks from the 1st (5), 3rd (99) and 6th (10) jars. So, the output is 114. Explanation added on 03-13-2025 :)
1 ≤ N ≤ 1000

input:
output: