bobby_k

Hops-telerik

Apr 5th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8. namespace Hops
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int[] field = Console.ReadLine().Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Select(item => int.Parse(item)).ToArray();
  15.             int numberDirections = int.Parse(Console.ReadLine());
  16.             int[] fieldCopy = new int[field.Length];
  17.             BigInteger max = int.MinValue;
  18.  
  19.             int index = 0;
  20.             for (int i = 0; i < numberDirections; i++)
  21.             {
  22.                 int[] directions = Console.ReadLine().Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Select(item => int.Parse(item)).ToArray();
  23.                 Array.Copy(field, fieldCopy, field.Length);
  24.                 BigInteger sum = fieldCopy[0];
  25.                 fieldCopy[0] = int.MaxValue;
  26.                 index = 0;
  27.                 for (int j = 0; j < directions.Length; j++)
  28.                 {
  29.                     if (directions[j] > 0)
  30.                     {
  31.                         index = index + directions[j];
  32.                         if (index > (fieldCopy.Length - 1) || fieldCopy[index] == int.MaxValue || directions[j] == 0)
  33.                         {
  34.                             break;
  35.                         }
  36.                         else
  37.                         {
  38.                             sum = sum + fieldCopy[index];
  39.                             fieldCopy[index] = int.MaxValue;
  40.                         }
  41.                     }
  42.                     else if (directions[j] < 0)
  43.                     {
  44.                         index = index + directions[j];
  45.                         if (index <= 0 || fieldCopy[index] == int.MaxValue || directions[j] == 0)
  46.                         {
  47.                             break;
  48.                         }
  49.                         else
  50.                         {
  51.                             sum = sum + fieldCopy[index];
  52.                             fieldCopy[index] = int.MaxValue;
  53.                         }
  54.                     }
  55.                 }
  56.                 if (sum > max)
  57.                 {
  58.                     max = sum;
  59.                 }
  60.             }
  61.             Console.WriteLine(max);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment