From 47a83937d726b97308c42c727446e046dadeca36 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 17 Jul 2025 12:57:36 +0900 Subject: [PATCH] =?UTF-8?q?[20250717]=20BOJ=20/=20P5=20/=20=ED=8C=80=20?= =?UTF-8?q?=EA=B5=AC=EC=84=B1=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 --- ... \355\214\200 \352\265\254\354\204\261.md" | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 "khj20006/202507/17 BOJ P5 \355\214\200 \352\265\254\354\204\261.md" diff --git "a/khj20006/202507/17 BOJ P5 \355\214\200 \352\265\254\354\204\261.md" "b/khj20006/202507/17 BOJ P5 \355\214\200 \352\265\254\354\204\261.md" new file mode 100644 index 00000000..d4a620c9 --- /dev/null +++ "b/khj20006/202507/17 BOJ P5 \355\214\200 \352\265\254\354\204\261.md" @@ -0,0 +1,117 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N, K; + static int[][] infos; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + public static void init() throws Exception { + + N = io.nextInt(); + K = io.nextInt(); + infos = new int[N][]; + for(int i=0;i a[1]==b[1] ? a[0]-b[0] : a[1]-b[1]); + int[] a = new int[N+1]; + int[] b = new int[N+1]; + for(int i=0;i= 4 && b[i] - b[i-3] <= K) { + List list1 = new ArrayList<>(); + for(int j=i-3;j<=i;j++) list1.add(a[j]); + Collections.sort(list1); + dp[i] = Math.max(dp[i], max[i-4] + a[i-3] + a[i-2] + a[i-1] + a[i] - list1.get(0)); + + if(i >= 5 && b[i] - b[i-4] <= K) { + list1 = new ArrayList<>(); + for(int j=i-4;j<=i;j++) list1.add(a[j]); + Collections.sort(list1); + dp[i] = Math.max(dp[i], max[i-5] + a[i-4] + a[i-3] + a[i-2] + a[i-1] + a[i] - list1.get(0) - list1.get(1)); + } + } + + max[i] = Math.max(max[i-1], dp[i]); + } + io.write(max[N] + "\n"); + + } + +} +```