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); + } +} +```