#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
#define MAXN 100005
#define FOR(i, a, b) for(int i = a; i <= b; i++)
int n, m, arr[MAXN];
int main(){
cin >> n >> m;
FOR(i, 1, n) cin >> arr[i];
sort(arr + 1, arr + 1 + n);
multiset<int> s;
FOR(i, 1, n - 1) s.insert(arr[i + 1] - arr[i] - 1);
int res = arr[n] - arr[1] + 1;
m = n - m;
while(s.size() && m){
res -= *(s.rbegin());
s.erase(s.find(*(s.rbegin())));
m--;
}
cout << res << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |