Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions JHLEE325/202511/05 BOJ G5 아우으 우아으이야!!.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
```java
import java.io.*;
import java.util.*;

public class Main {

static class line implements Comparable<line> {
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);
}
}
```