#include <bits/stdc++.h>
using namespace std;
deque <int> d;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
long long n , k, a[100005], ans=0;
cin >> n >> k;
k-=1;
for(int i=1; i<=n; i++){
cin >> a[i];
}
ans=a[1]-1;
for(int i=2; i<n; i++){
d.push_back(a[i]-a[i-1]);
}
sort(d.begin(), d.end());
for(int i=0; i<k; i++){
ans+=d[i];
}
cout<<a[n] - ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |