Skip to content

Commit 7a1eead

Browse files
authored
Create 2020-A-C.cpp
1 parent 0b7e81d commit 7a1eead

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

kick-start/2020-A-C.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

0 commit comments

Comments
 (0)