Advertisement
stoianpp

Greedy Dwarf

Dec 28th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. class GreedyDwarf
  7. {
  8.     static void Main()
  9.     {
  10.         char[] separators = { ',', ' ' };
  11.         string[] valley = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
  12.         int[] intValley = new int[valley.Length];
  13.         for (int i = 0; i < valley.Length; i++) intValley[i] = int.Parse(valley[i]);
  14.         int paths = int.Parse(Console.ReadLine());
  15.  
  16.         Queue<int[]> sequences = new Queue<int[]>();
  17.         for (int i = 0; i < paths; i++)
  18.         {
  19.             string[] temp = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
  20.             int[] tempInt = new int[temp.Length];
  21.             for (int g = 0; g < temp.Length; g++) tempInt[g] = int.Parse(temp[g]);
  22.             sequences.Enqueue(tempInt);
  23.         }
  24.        
  25.         BigInteger sum = long.MinValue;
  26.         while (sequences.Count > 0)
  27.         {
  28.             BigInteger currSum = 0;
  29.             int step = 0;
  30.             int[] path = sequences.Dequeue();
  31.             int[] checkArr = new int[intValley.Length];
  32.             Array.Copy(intValley, checkArr, intValley.Length);
  33.             int signPosition = 0;
  34.  
  35.             while (step >= 0 && step < checkArr.Length && checkArr[step] != 10001)
  36.             {
  37.                 currSum += checkArr[step];
  38.                 checkArr[step] = 10001;
  39.                 step += path[signPosition];
  40.                 if (signPosition < path.Length - 1) signPosition++;
  41.                 else { signPosition = 0; }
  42.             }
  43.             if (currSum > sum) sum = currSum;
  44.         }
  45.         Console.WriteLine(sum);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement