Skip to content

Commit 605b4d4

Browse files
authored
[20251219] BOJ / G5 / 흙길 보수하기 / 이인희
1 parent c52eb12 commit 605b4d4

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.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+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
int N = Integer.parseInt(st.nextToken());
10+
int L = Integer.parseInt(st.nextToken());
11+
12+
int[][] sections = new int[N][2];
13+
for(int i = 0; i < N; i++){
14+
st = new StringTokenizer(br.readLine());
15+
sections[i][0] = Integer.parseInt(st.nextToken());
16+
sections[i][1] = Integer.parseInt(st.nextToken());
17+
}
18+
Arrays.sort(sections, (a, b) -> a[0] - b[0]);
19+
int coveredEnd = 0;
20+
int answer = 0;
21+
22+
for(int i = 0; i < N; i++){
23+
int start = sections[i][0];
24+
int end = sections[i][1];
25+
if(coveredEnd >= end){
26+
continue;
27+
}
28+
29+
int realStart = Math.max(coveredEnd, start);
30+
int remain = end - realStart;
31+
int count = remain / L;
32+
if(remain % L != 0){
33+
count++;
34+
}
35+
answer += count;
36+
coveredEnd = realStart + count * L;
37+
}
38+
39+
System.out.println(answer);
40+
}
41+
}
42+
43+
```

0 commit comments

Comments
 (0)