#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define ll long long
#define pb push_back
#define endl '\n'
#define y1 y21
using namespace std;
const int inf = 1e9;
const int mxn = 2*1e5+11;
const int lg = 31;
const ll mod = 1e9+7;
void slve(){
int n,k;
cin>>n>>k;
vector<int> a(n), b;
for(int i=0; i<n; i++){
cin>>a[i];
if(i){
b.pb(a[i] - a[i-1] - 1);
}
}
int ans = a.back();
sort(b.rbegin(), b.rend());
for(int i=0; i<k-1; i++){
ans -= b[i];
}
cout<<ans;
}
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
ll T = 1;
// cin>>T;
while (T--) {
slve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |