#C3766. Maximum Gold Coins Collection
Maximum Gold Coins Collection
Maximum Gold Coins Collection
You are given a sequence of n boxes arranged in a row. Each box contains a certain number of gold coins. However, due to security restrictions, if you pick a box, you cannot pick its immediate neighbors. Your task is to determine the maximum total number of coins you can collect under this constraint.
You can formulate the problem using a dynamic programming approach. Let \(dp[i]\) represent the maximum number of coins that can be collected from the first \(i+1\) boxes. The recurrence relation can be written as:
[ dp[i] = \max(dp[i-1], dp[i-2] + coins[i]) ]
with the base cases:
[ dp[0] = coins[0], \quad dp[1] = \max(coins[0], coins[1]). ]
Your program should read the input from stdin and output the result to stdout.
inputFormat
The input consists of two lines:
- The first line contains an integer \(n\) — the number of boxes.
- The second line contains \(n\) space-separated integers, where each integer represents the number of coins in each box.
outputFormat
Output a single integer — the maximum number of coins that can be collected by picking boxes such that no two consecutive boxes are picked.
## sample1
10
10