#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n, k;
int keep[N];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
priority_queue<int> pq;
int pre = 0;
for( int i=0;i<n;i++ )
{
cin >> keep[i];
if(i>0) pq.push( keep[i]-pre );
pre = keep[i];
}
int ans = keep[n-1]-keep[0]+1;
for( int i=2;i<=k;i++ )
{
int temp = pq.top();
pq.pop();
ans -= temp-1;
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |