-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSolution.java
42 lines (34 loc) Β· 1.32 KB
/
Solution.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package Array.swea2001;
import java.io.*;
import java.util.*;
public class Solution {
static int T, N, M, max;
static int[][] map;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/Array/swea2001/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
map = new int[N][N];
max = Integer.MIN_VALUE;
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
map[i][j] = Integer.parseInt(st.nextToken());
if (i < M-1 || j < M-1) continue;
int sum = 0;
for (int m_i = i; m_i > i-M; m_i--) {
for (int m_j = j; m_j > j-M; m_j--) {
sum += map[m_i][m_j];
}
}
max = Math.max(max, sum);
}
}
System.out.println("#" + t + " " + max);
}
}
}