package oSWExpertAcademy;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class D2_1959 {
public static void main(String[]args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
int testCase = Integer.parseInt(br.readLine());
for(int tc=1; tc<=testCase; tc++) {
StringTokenizer st = new StringTokenizer(br.readLine());
//첫 배열의 크기
int Aj = Integer.parseInt(st.nextToken());
//두번째 배열의 크기
int Bj = Integer.parseInt(st.nextToken());
//첫 배열 생성
int fRow[] = new int[Aj];
//두번째 배열 생성
int sRow[] = new int[Bj];
//주어진 숫자를 첫번째 배열에 주입
st = new StringTokenizer(br.readLine());
for(int i=0; i<Aj; i++) {
fRow[i] = Integer.parseInt(st.nextToken());
}
//주어진 숫자를 두번째 배열에 주입
st = new StringTokenizer(br.readLine());
for(int j=0; j<Bj; j++) {
sRow[j] = Integer.parseInt(st.nextToken());
}
//최대값 초기화
int max = 0;
//첫번째 배열이 두번째 배열보다 작은 경우
if(Aj < Bj) {
for(int i=0; i<=Bj-Aj; i++) {
int sum = 0;
for(int k=0; k<Aj; k++) {
sum += fRow[k] * sRow[i+k];
}
max = Math.max(sum, max);
}
}
//첫번째 배열과 두번째 배열이 같을 경우
else if(Aj == Bj) {
for(int i=0; i<Aj; i++) {
max += fRow[i] * sRow[i];
}
}
//첫번재 배열이 두번째 배열보다 큰 경우
else {
for(int i=0; i<Aj-Bj; i++) {
int sum = 0;
for(int k=0; k<Bj; k++) {
sum += fRow[i+k] * sRow[k];
}
max = Math.max(sum, max);
}
}
System.out.println("#"+tc+" "+max);
}
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
댓글