-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYokanParty_001.java
More file actions
58 lines (49 loc) · 1001 Bytes
/
YokanParty_001.java
File metadata and controls
58 lines (49 loc) · 1001 Bytes
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
56
57
58
package java;
import java.util.*;
/**
* 001 - Yokan Party(★4)
* 貪欲法
* 二分探索法
*/
public class YokanParty_001 {
static int N;
static int L;
static int K;
static int[] A;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
L = sc.nextInt();
K = sc.nextInt();
A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = sc.nextInt();
}
/* 2分探索 */
int left = 0;
int right = L + 1;
while (right - left > 1) {
int mid = (int) (right + left) / 2;
if (isCutting(mid)) left = mid;
else right = mid;
}
System.out.println(left);
sc.close();
}
/**
* カット可能か判断
*
* @param c カット数
* @return boolean
*/
public static boolean isCutting(int c) {
int cnt = 0;
int pre = 0;
for (int i : A) {
if (i - pre < c || L - i < c) continue;
cnt++;
pre = i;
}
return cnt >= K;
}
}