-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProblemE.java
66 lines (60 loc) · 1.84 KB
/
ProblemE.java
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
59
60
61
62
63
64
65
66
/*
*
*/
import java.io.*;
import java.util.Arrays;
public class Main {
static class Reader {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StreamTokenizer st = new StreamTokenizer(bf);
public int nextInt() throws IOException {
st.nextToken();
return (int) st.nval;
}
public double nextDouble() throws IOException {
st.nextToken();
return st.nval;
}
public String nextLine() throws IOException {
return bf.readLine();
}
public boolean hasNext() throws IOException {
boolean b= st.nextToken() != StreamTokenizer.TT_EOF;
st.pushBack();
return b;
}
}
static PrintWriter out = new PrintWriter(System.out);
static Reader in = new Reader();
public static void main(String[] args) throws IOException {
while(in.hasNext()) {
int L = in.nextInt(), n = in.nextInt(), m = in.nextInt(), mt = m - 1, nt = n + 1;
int[] ns = new int[nt + 1];
for (int i = 1; i < nt; i++) {
ns[i] = in.nextInt();
}
ns[nt] = L;
Arrays.sort(ns);
int left = 1, right = L + 1, mid, k = Math.min(mt, n);
while (left < right) {
mid = (left + right) / 2;
int v = minE(ns, mid);
if (v <= k) right = mid;
else left = mid + 1;
}
out.println(right);
out.flush();
}
}
public static int minE(int[] ns, int lim){
int count=0,s=0;
for (int i = 1; i < ns.length; i++) {
if(ns[i]-ns[s]>lim){
if(s==--i) return Integer.MAX_VALUE;
s=i;
count++;
}
}
return count;
}
}