-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
61 lines (58 loc) · 1.47 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
61 lines (58 loc) · 1.47 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
diff --git a/CodeJam/Main.cpp b/examples/2020/KS_A/C/Main.cpp
index 2150379..220ca43 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2020/KS_A/C/Main.cpp
@@ -1570,11 +1570,56 @@ void init(){
cin >> T;
}
+ll N, K;
+v(ll) dAi;
+
void readInput(){
+ dAi.cl;
+ cin >> N >> K;
+ ll last, t;
+ cin >> last;
+ forn(i, N-1){
+ cin >> t;
+ dAi.pb(t-last);
+ last = t;
+ }
+ sort(all(dAi));
+}
+
+bool difficulty_possible(ll difficulty){
+ llog("difficulty", difficulty);
+ ll left_K = K;
+ forn(i, dAi.sz){
+ ll j = dAi.sz - i - 1;
+ ll cur_diff = dAi[j];
+ // after_diff = ceil(cur_diff / (cur_k + 1)) <= difficulty
+ // => cur_k >= cur_diff / difficulty - 1
+ // => min cur_k = ceil(cur_diff / difficulty) - 1
+ // cur_diff, difficulty, cur_k
+ // 13, 20, 0
+ // 19, 20, 0
+ // 20, 20, 0
+ // 21, 20, 1
+ left_K -= max<ll>(0,ceill(cur_diff, difficulty) - 1);
+ if(left_K < 0){
+ llog(dAi);
+ llog("not enough K", left_K, j);
+ return false;
+ }
+ if(cur_diff <= difficulty){
+ llog(dAi);
+ llog("enough K", left_K, j);
+ return true;
+ }
+ }
+ llog(dAi);
+ llog("enough K?", left_K);
+ return left_K >= 0;
}
// write to COMM_TYPE result
void calcFunction() {
+ result = lower_bound_function<ll,bool>(true, difficulty_possible, dAi.bk, 1);
}
} // namespace task