From 605b4d44175bd1c8b837b13888344d409c65cfdd Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Fri, 19 Dec 2025 23:57:51 +0900 Subject: [PATCH] =?UTF-8?q?[20251219]=20BOJ=20/=20G5=20/=20=ED=9D=99?= =?UTF-8?q?=EA=B8=B8=20=EB=B3=B4=EC=88=98=ED=95=98=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\354\210\230\355\225\230\352\270\260.md" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "LiiNi-coder/202512/19 BOJ \355\235\231\352\270\270 \353\263\264\354\210\230\355\225\230\352\270\260.md" diff --git "a/LiiNi-coder/202512/19 BOJ \355\235\231\352\270\270 \353\263\264\354\210\230\355\225\230\352\270\260.md" "b/LiiNi-coder/202512/19 BOJ \355\235\231\352\270\270 \353\263\264\354\210\230\355\225\230\352\270\260.md" new file mode 100644 index 00000000..1bdc6d55 --- /dev/null +++ "b/LiiNi-coder/202512/19 BOJ \355\235\231\352\270\270 \353\263\264\354\210\230\355\225\230\352\270\260.md" @@ -0,0 +1,43 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int L = Integer.parseInt(st.nextToken()); + + int[][] sections = new int[N][2]; + for(int i = 0; i < N; i++){ + st = new StringTokenizer(br.readLine()); + sections[i][0] = Integer.parseInt(st.nextToken()); + sections[i][1] = Integer.parseInt(st.nextToken()); + } + Arrays.sort(sections, (a, b) -> a[0] - b[0]); + int coveredEnd = 0; + int answer = 0; + + for(int i = 0; i < N; i++){ + int start = sections[i][0]; + int end = sections[i][1]; + if(coveredEnd >= end){ + continue; + } + + int realStart = Math.max(coveredEnd, start); + int remain = end - realStart; + int count = remain / L; + if(remain % L != 0){ + count++; + } + answer += count; + coveredEnd = realStart + count * L; + } + + System.out.println(answer); + } +} + +```