From e7cb490036faa01797e341ff131203be44afd5b0 Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 12 Feb 2025 10:29:18 +0900 Subject: [PATCH] =?UTF-8?q?[20250212]=20BOJ=20/=20G5=20/=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=EA=B2=8C=EC=9E=84=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\353\223\234\352\262\214\354\236\204.md" | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 "khj20006/202502/12 BOJ G5 \354\271\264\353\223\234\352\262\214\354\236\204.md" diff --git "a/khj20006/202502/12 BOJ G5 \354\271\264\353\223\234\352\262\214\354\236\204.md" "b/khj20006/202502/12 BOJ G5 \354\271\264\353\223\234\352\262\214\354\236\204.md" new file mode 100644 index 00000000..47390230 --- /dev/null +++ "b/khj20006/202502/12 BOJ G5 \354\271\264\353\223\234\352\262\214\354\236\204.md" @@ -0,0 +1,76 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + static int[][] dp; + static int[] A, B; + static int N; + static final int INF = (int)1e9 + 1; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + } + + static void ready() throws Exception{ + + N = Integer.parseInt(br.readLine()); + A = new int[N+1]; + B = new int[N+1]; + dp = new int[N+2][N+2]; + for(int i=0;i1 && A[i] > B[j-1] && dp[i][j-1] != INF) { + if(dp[i][j] == INF) dp[i][j] = dp[i][j-1] + B[j-1]; + else dp[i][j] = Math.max(dp[i][j], dp[i][j-1] + B[j-1]); + } + } + int ans = 0; + for(int i=1;i<=N+1;i++) { + if(dp[i][N+1] != INF) ans = Math.max(ans, dp[i][N+1]); + if(dp[N+1][i] != INF) ans = Math.max(ans, dp[N+1][i]); + } + bw.write(ans+"\n"); + + + } + +} + +```