From 00f377d4cef6852102a773b4b77d2f31c43e5da1 Mon Sep 17 00:00:00 2001 From: Donew <47556347+03do-new30@users.noreply.github.com> Date: Sat, 19 Jul 2025 22:10:09 +0900 Subject: [PATCH] =?UTF-8?q?[20250719]=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=8B=A0=EB=8F=99=EC=9C=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\354\234\274\354\235\264\354\225\274.md" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "03do-new30/202507/19 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/03do-new30/202507/19 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/03do-new30/202507/19 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..17c89c3a --- /dev/null +++ "b/03do-new30/202507/19 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,43 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + StringTokenizer st; + + int sum = 0; + boolean first = true; + int left = 0; + int right = 0; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + if (first) { + left = x; + right = y; + sum += y - x; + first = false; + continue; + } + + if (right <= x) { + sum += y - x; + left = x; + right = y; + } else { + if (y < right) continue; + int tmp = y - right; + sum += tmp; + right = y; + } + } + System.out.println(sum); + br.close(); + } +} +```