-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSWEA1959.java
More file actions
64 lines (51 loc) · 1.33 KB
/
SWEA1959.java
File metadata and controls
64 lines (51 loc) · 1.33 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.study.code.solved;
import java.util.Scanner;
public class SWEA1959 {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int tcN = sc.nextInt();
for (int tc = 1; tc <= tcN; tc++) {
int N = sc.nextInt();
int M = sc.nextInt();
int[] arrN = new int[N];
for (int i = 0; i < N; i++) {
arrN[i] = sc.nextInt();
}
int[] arrM = new int[M];
for (int i = 0; i < M; i++) {
arrM[i] = sc.nextInt();
}
int ans = 0;
int tmpAns = 0;
// MÀÌ Å«Áö NÀÌ Å«Áö
if(M>N) {
int tmp = 0;
for (int x = 0; x <= M-N; x++) {
tmpAns = 0;
for (int i = 0; i < N; i++) {
tmpAns += arrN[i]*arrM[i+tmp];
}
ans = Math.max(ans, tmpAns);
tmp++;
}
}else if(M<N) {
int tmp = 0;
for (int x = 0; x <= N-M; x++) {
tmpAns = 0;
for (int i = 0; i < M; i++) {
tmpAns += arrN[i+tmp]*arrM[i];
}
ans = Math.max(ans, tmpAns);
tmp++;
}
}else {
for (int i = 0; i < N; i++) {
ans += arrN[i]*arrM[i];
}
}
System.out.println("#"+ tc + " " + ans);
}
sc.close();
}
}