Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace JumpingSums2
- {
- class JumpingSums2
- {
- static void Main()
- {
- string input = Console.ReadLine();
- int jumps = int.Parse(Console.ReadLine());
- string[] splitInput = input.Split(' ');
- List<int> numbers = new List<int>();
- for (int i = 0; i < splitInput.Length; i++)
- {
- numbers.Add(Convert.ToInt32(splitInput[i].ToString()));
- }
- List<int> sums = new List<int>();
- for (int i = 0; i < numbers.Count; i++)
- {
- int tempSum = numbers[i];
- int currentIndex = i;
- for (int j = 0; j < jumps; j++)
- {
- currentIndex = (numbers[currentIndex]+currentIndex)%numbers.Count;
- tempSum += numbers[currentIndex];
- }
- sums.Add(tempSum);
- }
- Console.WriteLine("max sum = {0}",sums.Max());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment