From ac3afac39da950a8d61bacec9468f02bef94ad0a Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Sat, 28 Jun 2025 23:35:41 +0900 Subject: [PATCH] =?UTF-8?q?[20250628]=20BOJ=20/=20S1=20/=20=EC=8A=A4?= =?UTF-8?q?=ED=8B=B0=EC=BB=A4=20/=20=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \354\212\244\355\213\260\354\273\244.md" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "Seol-JY/202506/28 BOJ S1 \354\212\244\355\213\260\354\273\244.md" diff --git "a/Seol-JY/202506/28 BOJ S1 \354\212\244\355\213\260\354\273\244.md" "b/Seol-JY/202506/28 BOJ S1 \354\212\244\355\213\260\354\273\244.md" new file mode 100644 index 00000000..98b3a460 --- /dev/null +++ "b/Seol-JY/202506/28 BOJ S1 \354\212\244\355\213\260\354\273\244.md" @@ -0,0 +1,42 @@ +```java +import java.io.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int T = Integer.parseInt(br.readLine()); + + while (T-- > 0) { + int n = Integer.parseInt(br.readLine()); + + int[][] sticker = new int[2][n + 1]; + for (int i = 0; i < 2; i++) { + String[] line = br.readLine().split(" "); + for (int j = 1; j <= n; j++) { + sticker[i][j] = Integer.parseInt(line[j - 1]); + } + } + + int[][] dp = new int[2][n + 1]; + + dp[0][1] = sticker[0][1]; + dp[1][1] = sticker[1][1]; + + for (int i = 2; i <= n; i++) { + dp[0][i] = Math.max(dp[1][i - 1], dp[1][i - 2]) + sticker[0][i]; + dp[1][i] = Math.max(dp[0][i - 1], dp[0][i - 2]) + sticker[1][i]; + } + + int result = Math.max(dp[0][n], dp[1][n]); + bw.write(result + "\n"); + } + + bw.flush(); + bw.close(); + br.close(); + } +} + +```