Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class Program
- {
- static void Main()
- {
- int[] carrots = Console.ReadLine()
- .Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(x => int.Parse(x)).ToArray();
- int n = int.Parse(Console.ReadLine());
- int max = int.MinValue;
- int fieldLength = carrots.Length;
- for (int i = 0; i < n; i++)
- {
- int position = 0;
- HashSet<int> visitedPosition = new HashSet<int>();
- visitedPosition.Add(0);
- int sum = carrots[position];
- int[] directions = Console.ReadLine()
- .Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(x => int.Parse(x)).ToArray();
- int directionsCount = directions.Length;
- int tries = 0;
- while (true)
- {
- int choosenDirection = tries % directionsCount;
- position += directions[choosenDirection];
- if (position < 0 || position >= fieldLength || visitedPosition.Contains(position))
- {
- break;
- }
- sum += carrots[position];
- visitedPosition.Add(position);
- tries++;
- }
- if (max < sum)
- {
- max = sum;
- };
- }
- Console.WriteLine(max);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement