Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- using System.Collections.Generic;
- using System.Text;
- class GreedyDwarf
- {
- static void Main()
- {
- char[] separators = { ',', ' ' };
- string[] valley = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
- int[] intValley = new int[valley.Length];
- for (int i = 0; i < valley.Length; i++) intValley[i] = int.Parse(valley[i]);
- int paths = int.Parse(Console.ReadLine());
- Queue<int[]> sequences = new Queue<int[]>();
- for (int i = 0; i < paths; i++)
- {
- string[] temp = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
- int[] tempInt = new int[temp.Length];
- for (int g = 0; g < temp.Length; g++) tempInt[g] = int.Parse(temp[g]);
- sequences.Enqueue(tempInt);
- }
- BigInteger sum = long.MinValue;
- while (sequences.Count > 0)
- {
- BigInteger currSum = 0;
- int step = 0;
- int[] path = sequences.Dequeue();
- int[] checkArr = new int[intValley.Length];
- Array.Copy(intValley, checkArr, intValley.Length);
- int signPosition = 0;
- while (step >= 0 && step < checkArr.Length && checkArr[step] != 10001)
- {
- currSum += checkArr[step];
- checkArr[step] = 10001;
- step += path[signPosition];
- if (signPosition < path.Length - 1) signPosition++;
- else { signPosition = 0; }
- }
- if (currSum > sum) sum = currSum;
- }
- Console.WriteLine(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement