Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace MaximalSum
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] N = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int[,] matrix = new int[N[0], N[1]];
- string[,] submatrix = new string[3, 3];
- int sum = 0;
- int[] maxSum = new int[N[0]];
- Dictionary<int, string[,]> myDict = new Dictionary<int, string[,]>();
- for (int rows = 0; rows < N[0]; rows++)
- {
- int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- for (int cols = 0; cols < N[1]; cols++)
- {
- matrix[rows, cols] = numbers[cols];
- }
- }
- for (int rows = 0; rows < N[0] - 2; rows++)
- {
- for (int cols = 0; cols < N[1] - 3; cols++)
- {
- sum = matrix[rows, cols] + matrix[rows, cols + 1] + matrix[rows, cols + 2] + matrix[rows + 1, cols] + matrix[rows + 1, cols + 1] + matrix[rows + 1, cols + 2] + matrix[rows + 2, cols] + matrix[rows + 2, cols + 1] + matrix[rows + 2, cols + 2];
- submatrix[rows, cols] = matrix[rows, cols] +" "+ matrix[rows, cols + 1] +" "+ matrix[rows, cols + 2] +" "+ matrix[rows + 1, cols] +" "+ matrix[rows + 1, cols + 1] +" "+ matrix[rows + 1, cols + 2] +" "+ matrix[rows + 2, cols] +" "+ matrix[rows + 2, cols + 1] +" "+ matrix[rows + 2, cols + 2];
- myDict.Add(sum, submatrix);
- maxSum[cols] = sum;
- }
- }
- Console.WriteLine(maxSum.Max());
- string[,] result = new string[3, 3];
- myDict.TryGetValue(maxSum.Max(), out submatrix);
- Console.WriteLine(submatrix);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement