#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t n,k;cin>>n>>k;
vector<int64_t>arr(n);
for (int i =0;i<n;++i){
cin>>arr[i];
}
int64_t left =0,right = arr[n-1]+1;
while(left+1<right){
int64_t mid = (right+left)>>1;
int counts=1;
int64_t prev = arr[0];
for (int i =1;i<n;++i){
if (arr[i]+1-prev>mid){
counts++;
prev=arr[i];
}
}
if (counts>k){
left = mid;
}
else right = mid;
}
left++;
int64_t ans= 0;
int64_t prev =arr[0];
for (int i =1;i<n;++i){
if (arr[i]+1-prev>left){
ans+=arr[i-1]+1 - prev;
prev = arr[i];}}
ans+=arr[n-1]+1-prev;
cout<<ans<<endl;
}
//2 + 4 + 3 + 2 + 1
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |