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 _16.Hourglass_Sum
- {
- class Program
- {
- static void Main(string[] args)
- {
- long[][] matrix = new long[6][];
- for (int row = 0; row < matrix.Length; row++)
- {
- matrix[row] = Console.ReadLine().Split().Select(long.Parse).ToArray();
- }
- long maxSum = long.MinValue;
- for (int row = 0; row < matrix.Length - 2; row++)
- {
- for (int col = 0; col < matrix.Length - 2; col++)
- {
- long sum = (long)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 > maxSum)
- {
- maxSum = sum;
- }
- }
- }
- Console.WriteLine(maxSum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement