Akuna CapitalOA #21
Maximize Ratings
Estimated MediumJudge-ready
Topics (AI-labelled)DP Basics
Traverse the movie rating array in its original order and choose a subsequence that maximizes the sum of the chosen ratings. You may not skip two or more movies in a row; skipping a single movie at the start and at the end is allowed. There is no extra requirement to choose at least one movie: when n=1 you may skip the only movie, and an empty selection has a rating sum of 0; when n≥2 you cannot skip all of them.
Input
The first line contains n, and the second line contains n integers ratings[i]. Full original ranges: 1≤n≤100000, −1000≤ratings[i]≤1000.
Output
Output the maximum rating sum that satisfies the constraint, as an exact integer, with no modulo.
Example 1
Input:
6
-3 2 4 -1 -2 -5
Output:
4
Example 2
Input:
5
9 -1 -3 4 5
Output:
17
Example 3
Input:
1
-1000
Output:
0
Example notes
Original example 1 chooses [2,4,−2] for 4. Original example 2 chooses [9,−1,4,5] for 17, and the original output is kept; the original explanation omitted −1 and wrongly claimed 9+4+5=17 while skipping two movies in a row, which this site explicitly corrects. The original [-1,−3,−2] allows choosing only the second item, which shows that a single skip at the start and at the end is valid; the original has no non-empty requirement, and the third public example, a single −1000→0, is added by this site.
Editorial
Loading solution…