Skip to content

Commit 5d29f79

Browse files
authored
Merge pull request #1428 from AlgorithmWithGod/Seol-JY
[20251116] BOJ / G5 / 아우으 우아으이야!! / 설진영
2 parents 8169e39 + e42304a commit 5d29f79

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
9+
int n = Integer.parseInt(br.readLine());
10+
11+
if (n == 0) {
12+
System.out.println(0);
13+
return;
14+
}
15+
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
int currentStart = Integer.parseInt(st.nextToken());
18+
int currentEnd = Integer.parseInt(st.nextToken());
19+
20+
int totalLength = 0;
21+
22+
for (int i = 1; i < n; i++) {
23+
st = new StringTokenizer(br.readLine());
24+
int x = Integer.parseInt(st.nextToken());
25+
int y = Integer.parseInt(st.nextToken());
26+
27+
if (x <= currentEnd) {
28+
currentEnd = Math.max(currentEnd, y);
29+
} else {
30+
totalLength += (currentEnd - currentStart);
31+
currentStart = x;
32+
currentEnd = y;
33+
}
34+
}
35+
36+
totalLength += (currentEnd - currentStart);
37+
38+
System.out.println(totalLength);
39+
}
40+
}
41+
```

0 commit comments

Comments
 (0)