Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2.  
  3. namespace test
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] ratings = { -1, -2, -3, -4, -5 };
  10.  
  11.             Console.WriteLine(maximizeRatings(ratings));
  12.         }
  13.  
  14.      
  15.         static int maximizeRatings(int[] ratings)
  16.         {
  17.             int i = 2;
  18.             int[] answers = new int[ratings.Length];
  19.             if (ratings.Length == 0)
  20.                 return 0;
  21.  
  22.  
  23.             answers[0] = ratings[0];    
  24.             answers[1] = Math.Max(ratings[1], ratings[1] + answers[0]);
  25.             for (; i < ratings.Length; i++)
  26.             {
  27.                 answers[i] = Math.Max(answers[i - 1], answers[i - 2]) + ratings[i];
  28.             }
  29.             return Math.Max(answers[i - 2], answers[i-1]);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement