File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+
5
+
6
+ bool ok (int x,int k,const vector<int > & time){
7
+ int cnt = 0 ;
8
+ for (int i=1 ; i<time.size () ; ++i){
9
+
10
+ cnt += (time[i] - time[i-1 ] - 1 ) / x;
11
+ if (cnt > k)
12
+ return false ;
13
+ }
14
+ return cnt <=k;
15
+ }
16
+ void solve (){
17
+ int N, K;
18
+ cin >> N >> K;
19
+ vector<int > a (N,0 );
20
+ for (int i=0 ; i<N ; ++i)
21
+ cin >> a[i];
22
+ int left = 1 ;
23
+ int right = a.back () - a[0 ];
24
+ while (left <=right){
25
+ int mid = (left + right) >> 1 ;
26
+
27
+ if (ok (mid,K, a))right = mid -1 ;
28
+ else left = mid +1 ;
29
+ }
30
+ cout << right + 1 << " \n " ;
31
+ }
32
+
33
+ int main (){
34
+ int T;
35
+ cin >> T;
36
+
37
+ for (int t =1 ; t <= T ; ++ t){
38
+ cout << " Case #" <<t<<" : " ;
39
+
40
+ solve ();
41
+ }
42
+ return 0 ;
43
+ }
You can’t perform that action at this time.
0 commit comments