Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace test
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] ratings = { -1, -2, -3, -4, -5 };
- Console.WriteLine(maximizeRatings(ratings));
- }
- static int maximizeRatings(int[] ratings)
- {
- int i = 2;
- int[] answers = new int[ratings.Length];
- if (ratings.Length == 0)
- return 0;
- answers[0] = ratings[0];
- answers[1] = Math.Max(ratings[1], ratings[1] + answers[0]);
- for (; i < ratings.Length; i++)
- {
- answers[i] = Math.Max(answers[i - 1], answers[i - 2]) + ratings[i];
- }
- return Math.Max(answers[i - 2], answers[i-1]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement