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 Task3
- {
- class Program
- {
- static void Main(string[] args)
- {
- //sizes of pattern
- const int heightSize = 3;
- const int lengthSize = 5;
- int n = int.Parse(Console.ReadLine());
- int[,] matrix = new int[n, n];
- int rows = n;
- int cols = n;
- for (int row = 0; row < rows; row++)
- {
- string line = Console.ReadLine();
- string[] lineArr = line.Split(' ');
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = int.Parse(lineArr[col]);
- }
- }
- int maxSum = int.MinValue;
- int currentSum = 0;
- for (int row = 0; row < matrix.GetLength(0)-heightSize+1; row++)
- {
- int[,] bigMatrix = new int[3, 5];
- for (int col = 0; col < matrix.GetLength(1)-lengthSize+1; col++)
- {
- for (int i = 0; i < bigMatrix.GetLength(0); i++)
- {
- for (int k = 0; k < bigMatrix.GetLength(1); k++)
- {
- currentSum += matrix[row + i, col + k];
- bigMatrix[i,k] = matrix[row + i, col + k];
- }
- }
- if (!IsSequened(bigMatrix))
- {
- currentSum = 0;
- continue;
- }
- currentSum -= bigMatrix[0, 3];
- currentSum -= bigMatrix[0, 4];
- currentSum -= bigMatrix[1, 3];
- currentSum -= bigMatrix[1, 4];
- currentSum -= bigMatrix[1, 0];
- currentSum -= bigMatrix[1, 1];
- currentSum -= bigMatrix[2, 0];
- currentSum -= bigMatrix[2, 1];
- if (currentSum > maxSum)
- {
- maxSum = currentSum;
- currentSum = 0;
- }
- }
- }
- Console.Write("YES ");
- Console.WriteLine(maxSum);
- }
- private static bool IsSequened(int[,] bigMatrix)
- {
- if (bigMatrix[0,0] == bigMatrix[0,1]-1 &&
- bigMatrix[0,1] == bigMatrix[0,2]-1 &&
- bigMatrix[0,2] == bigMatrix[1,2]-1 &&
- bigMatrix[1,2] == bigMatrix[2,2]-1 &&
- bigMatrix[2,2] == bigMatrix[2,3]-1 &&
- bigMatrix[2,3] == bigMatrix[2,4]-1)
- {
- return true;
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement