This repository was archived by the owner on Dec 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOJ9465.java
More file actions
40 lines (29 loc) · 1.3 KB
/
Copy pathBOJ9465.java
File metadata and controls
40 lines (29 loc) · 1.3 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
import java.util.Scanner;
public class BOJ9465 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int total = scanner.nextInt();
for (int i = 0; i < total; i++) {
int num = scanner.nextInt();
int[][][] intArray = new int[2][num][2];
for (int j = 0; j < 2; j++) {
for (int k = 0; k < num; k++) {
intArray[j][k][0] = scanner.nextInt();
}
}
intArray[0][0][1] = intArray[0][0][0];
intArray[1][0][1] = intArray[1][0][0];
if(num == 1) {
System.out.println(Math.max(intArray[0][0][1], intArray[1][0][1]));
return;
}
intArray[0][1][1] = intArray[0][1][0] + intArray[1][0][1];
intArray[1][1][1] = intArray[1][1][0] + intArray[0][0][1];
for (int j = 2; j < num; j++) {
intArray[0][j][1] = Math.max(intArray[1][j - 1][1], intArray[1][j - 2][1]) + intArray[0][j][0];
intArray[1][j][1] = Math.max(intArray[0][j - 1][1], intArray[0][j - 2][1]) + intArray[1][j][0];
}
System.out.println(Math.max(intArray[0][num - 1][1], intArray[1][num - 1][1]));
}
}
}