-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCuttingLog
More file actions
92 lines (86 loc) · 2.2 KB
/
CuttingLog
File metadata and controls
92 lines (86 loc) · 2.2 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* #1114
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.Collator;
import java.util.*;
public class Main {
public static void main(String[] args) {
new Sol();
}
}
class Sol{
int L, C, K;
private final Buf buf = new Buf();
List<Integer> input = new ArrayList<>();
public Sol(){
L = buf.readInt();
K = buf.readInt();
C = buf.readInt();
Set<Integer> inputSet = new HashSet<>();
for (int i = 0; i<K; i++){
inputSet.add(buf.readInt());
}
input.addAll(inputSet);
input.add(L);
input.sort(Comparator.comparingInt(o -> o));
int right = L;
int left = 0;
while(left<right){
int mid = (right+left)/2;
if (isCan(0, 0, mid)){
right = mid;
}else{
left = mid+1;
}
}
int result = 0;
for (int i = 0; i<input.size(); i++){
if (isCan(input.get(i), 1, left)){
result = input.get(i);
break;
}
}
System.out.println(right + " " + result);
}
public boolean isCan(int tmp, int idx, int mid){
int pre = 0;
boolean isCan = false;
for(int i =0; i<input.size();){
if (input.get(i)<=tmp+mid){
isCan = true;
pre = input.get(i);
i++;
}
else{
if (!isCan)return false;
isCan=false;
tmp = pre;
idx++;
}
}
return idx<=C;
}
}
class Buf{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
public String read(){
while(st==null||!st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}catch(IOException e){
return null;
}
}
return st.nextToken();
}
public Integer readInt(){
return Integer.parseInt(read());
}
public Long readLong(){
return Long.parseLong(read());
}
}