Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _05.Max_Platform_3_x_3
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] pos = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int rows = pos[0];
- int cols = pos[1];
- int[][] matrix = new int[rows][];
- for (int i = 0; i < rows; i++)
- {
- matrix[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- }
- long maxSum = int.MinValue;
- int startRow = 0;
- int startCol = 0;
- for (int i = 0; i < rows - 2; i++)
- {
- for (int j = 0; j < cols - 2; j++)
- {
- long sum = TmpSum(matrix, i, j);
- if (maxSum < sum)
- {
- maxSum = sum;
- startRow = i;
- startCol = j;
- }
- }
- }
- Console.WriteLine(maxSum);
- for (int i = startRow; i < startRow + 3; i++)
- {
- for (int j = startCol; j < startCol + 3; j++)
- {
- Console.Write(matrix[i][j] + " ");
- }
- Console.WriteLine();
- }
- }
- static long TmpSum(int[][] matrix,int row,int col)
- {
- long sum = 0;
- for (int tmpRow = row; tmpRow < row+3; tmpRow++)
- {
- for (int tmpCol = col; tmpCol < col+3; tmpCol++)
- {
- sum += matrix[tmpRow][tmpCol];
- }
- }
- return sum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement