svetlozar_kirkov

Jumping Sums (100/100)

Nov 20th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace JumpingSums2
  6. {
  7.     class JumpingSums2
  8.     {
  9.         static void Main()
  10.         {
  11.             string input = Console.ReadLine();
  12.             int jumps = int.Parse(Console.ReadLine());
  13.             string[] splitInput = input.Split(' ');
  14.             List<int> numbers = new List<int>();
  15.             for (int i = 0; i < splitInput.Length; i++)
  16.             {
  17.                 numbers.Add(Convert.ToInt32(splitInput[i].ToString()));
  18.             }
  19.             List<int> sums = new List<int>();
  20.             for (int i = 0; i < numbers.Count; i++)
  21.             {
  22.                 int tempSum = numbers[i];
  23.                 int currentIndex = i;
  24.  
  25.                 for (int j = 0; j < jumps; j++)
  26.                 {
  27.                     currentIndex = (numbers[currentIndex]+currentIndex)%numbers.Count;
  28.                     tempSum += numbers[currentIndex];
  29.                 }
  30.                 sums.Add(tempSum);
  31.             }
  32.             Console.WriteLine("max sum = {0}",sums.Max());
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment