#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];
}
vector<int64_t>brr;
for (int i =1;i<n;++i){
brr.push_back(arr[i]-arr[i-1]-1);
}
sort(brr.rbegin(),brr.rend());
int64_t ans = arr[n-1]+1-arr[0];
for (int i =0;i<k;++i)ans-=brr[i];
cout<<ans<<endl;}
//2 + 4 + 3 + 2 + 1
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |