Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
- var rows = input[0];
- var cols = input[1];
- var matrix = new int[rows, cols];
- for (var row = 0; row < matrix.GetLength(0); row++)
- {
- var inputElement = Console.ReadLine().Split().Select(int.Parse).ToArray();
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = inputElement[col];
- }
- }
- var subMatrixRow = int.Parse(Console.ReadLine());
- var subMatrixCol = int.Parse(Console.ReadLine());
- var maxSum = int.MinValue;
- var startRowIndex = 0;
- var startColIndex = 0;
- if (subMatrixRow <= matrix.GetLength(0) && subMatrixCol <= matrix.GetLength(1))
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- var tempMaxSum = 0;
- if (row + subMatrixRow <= matrix.GetLength(0) && col + subMatrixCol <= matrix.GetLength(1))
- {
- for (int i = row; i < row + subMatrixRow; i++)
- {
- for (int j = col; j < col + subMatrixCol; j++)
- {
- tempMaxSum += matrix[i, j];
- }
- }
- }
- if (tempMaxSum > maxSum)
- {
- maxSum = tempMaxSum;
- startRowIndex = row;
- startColIndex = col;
- }
- }
- }
- }
- for (int row = 0; row < subMatrixRow; row++)
- {
- for (int col = 0; col < subMatrixCol; col++)
- {
- Console.Write(matrix[startRowIndex + row, startColIndex + col] + " ");
- }
- Console.WriteLine();
- }
- Console.WriteLine(maxSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement