#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
using namespace std;
#define int long long
int mod = 1e18 + 7;
signed main(){
int n , k , mx = 0;
cin >> n >> k;
int a[n];
vector <int> v;
for(int i = 0; i < n; i++){
cin >> a[i];
if(i != 0){
v.push_back(abs(a[i] - a[i - 1]));
}
mx = max(mx , a[i]);
}
if(k == n){
cout << n;
return 0;
}
if(k == 1){
cout << mx ;
return 0;
}
sort(v.begin() ,v.end() );
reverse(v.begin() , v.end() );
// mx++;
int s = v.size();
for(int i = 0; i < min(s , k - 1LL); i++){
mx -= v[i] - 1;
}
cout << mx;
return 0;
}
//AZIM_BEST
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |