-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHourGlass.java
More file actions
28 lines (21 loc) · 758 Bytes
/
HourGlass.java
File metadata and controls
28 lines (21 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;
public class HourGlass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int r = sc.nextInt();
int c = sc.nextInt();
int a[][] = new int[r][c];
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
a[i][j] = sc.nextInt();
int max = Integer.MIN_VALUE;
for (int i = 0; i < r - 2; i++)
for (int j = 0; j < c - 2; j++) {
int sum = a[i][j] + a[i][j + 1] + a[i][j + 2]
+ a[i + 1][j + 1] +
a[i + 2][j] + a[i + 2][j + 1] + a[i + 2][j + 2];
max = Math.max(max, sum);
}
System.out.println(max);
}
}