Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace MatrixMaxSum
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- int[,] matrix = FillMatrix(size);
- int[] coordinates = Console.ReadLine().
- Split().
- Select(int.Parse).
- ToArray();
- int maxSum = int.MinValue;
- int currSum = 0;
- int counter = 0;
- for (int i = 0; i < coordinates.Length; i += 2)
- {
- int[] currCoordinates = coordinates.Skip(i)
- .Take(2)
- .ToArray();
- int currRow = currCoordinates[0];
- int currCol = currCoordinates[1];
- while (currRow > 0)
- {
- for (int j = currRow; j <= currRow; j++)
- {
- for (int k = 0; k <= currCol; k++)
- {
- currSum += matrix[j,k];
- }
- }
- currRow--;
- }
- }
- }
- public static int[,] FillMatrix(int size)
- {
- int[,] matrix = new int[size, size];
- for (int row = 0; row < size; row++)
- {
- int[] currLine = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- for (int col = 0; col < size; col++)
- {
- matrix[row, col] = currLine[col];
- }
- }
- return matrix;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment