-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path어두운 굴다리.java
More file actions
55 lines (43 loc) · 1.33 KB
/
어두운 굴다리.java
File metadata and controls
55 lines (43 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int[] arr;
static int n;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
int m = Integer.parseInt(br.readLine());
arr = new int[m];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < m; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int start = 0, end = n, res = 0;
while (start <= end) {
int mid = start + (end - start) / 2;
if (lightCheck(mid)) {
res = mid;
end = mid - 1;
} else {
start = mid + 1;
}
}
System.out.println(res);
}
private static boolean lightCheck(int mid) {
int prev = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] - mid <= prev) {
prev = arr[i] + mid;
} else {
return false;
}
}
if (n - prev > 0) {
return false;
}
return true;
}
}