← 返回 oracle 的题目列表Maximum Movie Rating with No Two Consecutive Skips
类型:online_judge
Given an integer array ratings, where ratings[i] is the rating of movie i, ratings may be positive, zero, or negative. You may watch a movie and collect its rating, or skip it.
Compute the maximum total rating subject to this constraint: you may not skip two or more consecutive movies. Equivalently, at least one movie in every adjacent pair must be watched.
When there is only one movie, skipping it is allowed, so the answer may be 0.
Input
n
r1 r2 ... rn
Output
maximum total rating
Constraints
0 <= n <= 2 * 10^5
-10^9 <= ratings[i] <= 10^9
Example
Input:
5
5 -10 4 3 -2
Output:
12
Explanation: watch movies 1, 3, and 4, and skip movies 2 and 5, for a total of 5 + 4 + 3 = 12.
Example
Input
5
5 -10 4 3 -2
Output
12