#K92732. Maximum Likes from Non-Consecutive Posts

    ID: 38263 Type: Default 1000ms 256MiB

Maximum Likes from Non-Consecutive Posts

Maximum Likes from Non-Consecutive Posts

You are given an array \(A\) of \(n\) non-negative integers, where \(A[i]\) represents the number of likes on the \(i\text{-th}\) post. Your task is to select some posts such that no two selected posts are consecutive, and maximize the total number of likes collected.

Formally, let \(dp[i]\) be the maximum total likes using posts up to index \(i\). Then, the recurrence relation is given by:

[ dp[i] = \max(dp[i-1],;dp[i-2] + A[i]) ]

Input is read from standard input and output should be written to standard output.

inputFormat

The first line contains a single integer \(n\) (where \(0 \le n \le 10^5\)), representing the number of posts.

The second line contains \(n\) space-separated integers, each representing the number of likes for a post. If \(n = 0\), the second line will be empty.

outputFormat

Output a single integer which is the maximum total likes that can be collected from the posts, following the rule that no two selected posts are consecutive.

## sample
5
3 2 5 10 7
15

</p>