#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,k;
cin >> n >> k;
ll a[n];
for(ll i = 0;i < n;i++)
{
cin >> a[i];
}
sort(a,a+n);
ll ans=a[n-1];
vector<ll> v;
for(ll i = 1;i < n;i++)
{
v.push_back(a[i]-a[i-1]-1);
}
sort(v.begin(),v.end());
k--;
for(ll i = v.size()-1;k!=0;i--)
{
ans-=v[i];
k--;
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 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 |
0 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 |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |