From 3d3c85bbaad2680c68791d068bcf05f18a56b3e2 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 24 Jul 2025 09:22:30 +0900 Subject: [PATCH] =?UTF-8?q?[20250724]=20BOJ=20/=20P5=20/=20=EB=A7=89?= =?UTF-8?q?=EB=8C=80=EA=B8=B0=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 --- ...5 \353\247\211\353\214\200\352\270\260.md" | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 "khj20006/202507/24 BOJ P5 \353\247\211\353\214\200\352\270\260.md" diff --git "a/khj20006/202507/24 BOJ P5 \353\247\211\353\214\200\352\270\260.md" "b/khj20006/202507/24 BOJ P5 \353\247\211\353\214\200\352\270\260.md" new file mode 100644 index 00000000..7f532970 --- /dev/null +++ "b/khj20006/202507/24 BOJ P5 \353\247\211\353\214\200\352\270\260.md" @@ -0,0 +1,102 @@ +```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, L; + static int[][] infos; + static TreeMap h, l; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + static void init() throws Exception { + + N = io.nextInt(); + L = io.nextInt(); + infos = new int[N][2]; + for(int i=0;i(); + l = new TreeMap<>(); + + } + + static void solve() throws Exception { + + Arrays.sort(infos, (a,b) -> a[1]==b[1] ? a[0]-b[0] : a[1]-b[1]); + long ans = 0; + for(int[] info : infos) { + int t = info[0], d = info[1]; + long hValue = h.getOrDefault(t, 0L); + long hRes = Math.max(hValue, l.getOrDefault(d,0L) + Math.abs(t-d) + L); + long lValue = l.getOrDefault(d, 0L); + long lRes = Math.max(lValue, Math.max(lValue, h.getOrDefault(t, 0L) + Math.abs(t-d) + L)); + h.put(t, hRes); + l.put(d, lRes); + ans = Math.max(ans, Math.max(hRes, lRes)); + } + io.write(ans + "\n"); + + + } + +} +```