Question
The Cursed Isles of Greed
You are a daring treasure hunter sailing across a chain of mystical islands, each hiding a stash of gold coins.
However, a stronger curse binds the isles — if you loot the i-th island, you cannot loot the next two islands (i + 1 and i + 2). You may resume looting from the (i + 3)-th island.
Given an integer array nums, where nums[i] represents the gold on the i-th island, return the maximum treasure you can loot without breaking the curse.
Input
The first line of input contains a single integer n — representing the number of islands.
The second line of input contains n space-separated integers, where each integer represents the amount of gold on that island.
The second line of input contains n space-separated integers, where each integer represents the amount of gold on that island.
Output
Return a single integer — the maximum treasure that can be looted without breaking the curse.
Example
Input:
6
2 7 9 3 1 5
Output:
14
Explanation:
Possible combination for maximum loot will be: 9 + 5 = 14.
6
2 7 9 3 1 5
Output:
14
Explanation:
Possible combination for maximum loot will be: 9 + 5 = 14.