Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Core_Tasks_2
- {
- class Program
- {
- static void Main(string[] args)
- {
- //int size = 5;
- int size = Int32.Parse(Console.ReadLine());
- string[][] matrix = new string[size][];
- //int[][] matrix = new int[][]
- //{
- // new int[] { 1, 22, 3, 41, 5, 2 },
- // new int[] { 2, 13, 4, -5, 6, 5 },
- // new int[] { -6, 5, 9, 31, 2, 8 },
- // new int[] { 3, 14, 5, -6, 7, 4 },
- // new int[] { 4, -5, 6, -7, 8, 7 },
- //};
- long sum = Int64.MinValue;
- for (int row = 0; row < size; row++)
- {
- matrix[row] = Console.ReadLine().Split(' ');
- }
- //int[] rc = "-3 -3 3 3 4 -3 -4 3".Split(' ').Select(n => Int32.Parse(n)).ToArray();
- int[] rc = Console.ReadLine().Split(' ').Select(n => Int32.Parse(n)).ToArray();
- for (int i = 0; i < rc.Length; i += 2)
- {
- int rowLength = matrix[0].Length;
- int r = rc[i];
- int c = rc[i + 1];
- Console.WriteLine(r + " " + c);
- int sPointX = 0;
- int sPointY = 0;
- int ePointX = 0;
- int ePointY = 0;
- if (r < 0)
- {
- sPointX = rowLength - 1;
- sPointY = Math.Abs(r) - 1;
- }
- else
- {
- sPointX = 0;
- sPointY = r - 1;
- }
- if (c < 0)
- {
- ePointX = Math.Abs(c) - 1;
- ePointY = size - 1;
- }
- else
- {
- ePointX = c - 1;
- ePointY = 0;
- }
- //Console.WriteLine("Initial Y: " + sPointY + " X: " + sPointX);
- bool alive = true;
- bool horizontal = true;
- bool vertical = false;
- int tmpSum = 0;
- //Console.WriteLine();
- while (alive)
- {
- //Console.WriteLine("Sequence: " + matrix[sPointY][sPointX]);
- //Console.WriteLine("Y: " + sPointY + " X: " +sPointX);
- tmpSum += Int32.Parse(matrix[sPointY][sPointX]);
- if (sPointX == ePointX && sPointY == ePointY)
- break;
- if (r < 0)
- {
- if (sPointX == ePointX)
- {
- horizontal = false;
- vertical = true;
- }
- if (horizontal)
- {
- sPointX--;
- }
- }
- else
- {
- if (sPointX == ePointX)
- {
- horizontal = false;
- vertical = true;
- }
- if (horizontal)
- {
- sPointX++;
- }
- }
- if (c < 0)
- {
- if (sPointY == ePointY)
- {
- vertical = true;
- }
- if (vertical)
- {
- sPointY++;
- }
- }
- else
- {
- if (sPointY == ePointY)
- {
- vertical = false;
- }
- if (vertical)
- {
- sPointY--;
- }
- }
- }
- //Console.WriteLine(tmpSum);
- if (tmpSum > sum)
- sum = tmpSum;
- }
- Console.WriteLine(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement