Problem Solving/BOJ
[Silver 1] 9465번 스티커
kmkunk
2022. 3. 29. 18:26
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
int[][] dp = new int[100_001][3];
while(t-- > 0) {
int n = Integer.parseInt(br.readLine());
String[] arr1 = br.readLine().split(" ");
String[] arr2 = br.readLine().split(" ");
int max = 0;
for(int i=1; i<=n; i++) {
dp[i][0] = Math.max(dp[i-1][0], Math.max(dp[i-1][1], dp[i-1][2]));
dp[i][1] = Math.max(dp[i-1][0], dp[i-1][2])+Integer.parseInt(arr1[i-1]);
dp[i][2] = Math.max(dp[i-1][0], dp[i-1][1])+Integer.parseInt(arr2[i-1]);
}
max = Math.max(dp[n][0], Math.max(dp[n][1], dp[n][2]));
System.out.println(max);
}
}
}