Skip to content

Commit 3d6f67a

Browse files
authored
[20250710] BOJ / G4 / 휴게소 세우기 / 김수연
1 parent 99f48c6 commit 3d6f67a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = nextInt();
14+
int M = nextInt();
15+
int L = nextInt();
16+
if (N > 0) nextLine();
17+
int[] pos = new int[N+2];
18+
pos[0] = 0;
19+
for (int i = 1; i <= N; i++) pos[i] = nextInt();
20+
pos[N+1] = L;
21+
Arrays.sort(pos);
22+
23+
int start = 1, end = L-1;
24+
while (start <= end) {
25+
int mid = (start + end) / 2;
26+
int cnt = 0;
27+
for (int i = 1; i < N+2; i++) cnt += ((pos[i] - pos[i-1] - 1) / mid);
28+
29+
if (cnt > M) start = mid + 1;
30+
else end = mid - 1;
31+
}
32+
System.out.println(start);
33+
}
34+
}
35+
```

0 commit comments

Comments
 (0)