Hourglass Sum - List and Matricies - Exercises
Привет отново, програмата ми не минава един от тестовете и остава на 83 точки.
Проверих другата тема, в която проблемът е същия като моя, но там алгоритъма е друг, така че не можах да си помогна.
Поради тази причина създадох тази тема.
Условие: https://softuni.bg/downloads/svn/soft-tech/May-2016/Programming-Fundamentals-May-2016/04.%20Programming-Fundamentals-Lists-and-Matrices/04.%20Programming-Fundamentals-Lists-and-Matrices-Exercises.docx
Код:
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        int rows = 6;
        int cols = 6;
        int[][] matrix = new int[rows][];
        for (int row = 0; row < rows; row++)
        {
            matrix[row] = Console.ReadLine().Split().Select(int.Parse).ToArray();
        }
        int maxValue = int.MinValue;
        for (int row = 0; row < rows-2; row++)
        {
            for (int col = 0; col < cols-2; col++)
            {
                int sum = 0;
                if (matrix[row][col]>0)
                {
                    sum = matrix[row][col] + matrix[row][col + 1] + matrix[row][col + 2]
                        + matrix[row + 1][col + 1]
                        + matrix[row + 2][col] + matrix[row + 2][col + 1]+ matrix[row + 2][col + 2];
                }
                if (sum>maxValue)
                {
                    maxValue = sum;
                }
            }
        }
        Console.WriteLine(maxValue);
    }
}
Благодаря предварително!