From a773ba2e88ba39f46ba6558fb673e2c8ff70e735 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Wed, 5 Nov 2025 08:08:21 +0900 Subject: [PATCH] =?UTF-8?q?[20251105]=20BOJ=20/=20G5=20/=20=EC=95=84?= =?UTF-8?q?=EC=9A=B0=EC=9C=BC=20=EC=9A=B0=EC=95=84=EC=9C=BC=EC=9D=B4?= =?UTF-8?q?=EC=95=BC!!=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\234\274\354\235\264\354\225\274!!.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "JHLEE325/202511/05 BOJ G5 \354\225\204\354\232\260\354\234\274 \354\232\260\354\225\204\354\234\274\354\235\264\354\225\274!!.md" diff --git "a/JHLEE325/202511/05 BOJ G5 \354\225\204\354\232\260\354\234\274 \354\232\260\354\225\204\354\234\274\354\235\264\354\225\274!!.md" "b/JHLEE325/202511/05 BOJ G5 \354\225\204\354\232\260\354\234\274 \354\232\260\354\225\204\354\234\274\354\235\264\354\225\274!!.md" new file mode 100644 index 00000000..a04a197a --- /dev/null +++ "b/JHLEE325/202511/05 BOJ G5 \354\225\204\354\232\260\354\234\274 \354\232\260\354\225\204\354\234\274\354\235\264\354\225\274!!.md" @@ -0,0 +1,53 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static class line implements Comparable { + int x, y; + line(int x, int y) { this.x = x; this.y = y; } + @Override + public int compareTo(line o) { + if (this.x != o.x) return Integer.compare(this.x, o.x); + return Integer.compare(this.y, o.y); + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + + line[] arr = new line[N]; + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + arr[i] = new line(a, b); + } + Arrays.sort(arr); + + long res = 0; + int x = arr[0].x; + int y = arr[0].y; + + for (int i = 1; i < N; i++) { + int ns = arr[i].x; + int ne = arr[i].y; + if (ns <= y) { + if (ne > y) { + y = ne; + } + } else { + res += (long)(y - x); + x = ns; + y = ne; + } + } + res += (long)(y - x); + + System.out.println(res); + } +} +```