Advertisement
esend3

Hourglass Sum

Sep 14th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _16.Hourglass_Sum
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. long[][] matrix = new long[6][];
  14.  
  15. for (int row = 0; row < matrix.Length; row++)
  16. {
  17. matrix[row] = Console.ReadLine().Split().Select(long.Parse).ToArray();
  18. }
  19.  
  20. long maxSum = long.MinValue;
  21.  
  22. for (int row = 0; row < matrix.Length - 2; row++)
  23. {
  24. for (int col = 0; col < matrix.Length - 2; col++)
  25. {
  26. long sum = (long)matrix[row][col] + matrix[row][col + 1] + matrix[row][col + 2] +
  27. matrix[row + 1][col + 1] +
  28. matrix[row + 2][col] + matrix[row + 2][col + 1] + matrix[row + 2][col + 2];
  29.  
  30. if (sum > maxSum)
  31. {
  32. maxSum = sum;
  33. }
  34. }
  35. }
  36. Console.WriteLine(maxSum);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement