package oSWExpertAcademy;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//파리퇴치
public class D2_04 {
public static void main(String[]args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
int tcase = Integer.parseInt(br.readLine());
for(int i=1; i<=tcase; i++) {
String[] arr = br.readLine().split(" ");
int N = Integer.parseInt(arr[0]);
int M = Integer.parseInt(arr[1]);
int max = 0;
int[][] area = new int[N][N];
//area에 파리갯수 넣기
for(int x = 0; x<N; x++) {
String[] flys = br.readLine().split(" ");
for(int y=0; y<N; y++) {
area[x][y] = Integer.parseInt(flys[y]);
}
}
for(int x=0; x<=N-M; x++) {
for(int y=0; y<=N-M; y++) {
//죽은 파리의 수 합
int sum = 0;
for(int a=x; a<x+M; a++) {
for(int b=y; b<y+M; b++) {
sum += area[a][b];
}
}
if(max < sum) {
max = sum;
}
}
}
System.out.println("#"+i+" "+max);
}
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
댓글