#K77887. Maximum Coins Collection

    ID: 34964 Type: Default 1000ms 256MiB

Maximum Coins Collection

Maximum Coins Collection

You are given a tower with n levels. Each level i has an associated number of coins given by coins[i]. Your task is to collect the maximum number of coins by selecting levels such that you never collect coins from two consecutive levels. In other words, if you collect coins from level i, you cannot collect coins from level i-1 or i+1.

The recurrence relation for the problem is given by: $$dp[i] = \max(dp[i-1], coins[i] + dp[i-2])$$ where dp[i] denotes the maximum coins collectible from the first i+1 levels.

Find the maximum coins that can be collected given the number of levels and the coin values at each level.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer n, the number of levels.
  • The second line contains n space-separated integers representing the number of coins at each level.

outputFormat

Output a single integer on stdout which is the maximum number of coins that can be collected.

## sample
1
5
5

</p>