Skip to content

Commit ada008e

Browse files
authored
Merge pull request #503 from AlgorithmWithGod/03do-new30
[20250719] BOJ / G5 / 아우으 우아으이야!! / 신동윤
2 parents a1b8f6a + 00f377d commit ada008e

File tree

1 file changed

+43
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)