This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define forin(i,a,b) for(int i=a; i <= b; i++)
#define forde(i, a, b) for(int i = a; i <= b; i--)
using namespace std;
const int N = 1e5 + 10;
long long a[N], b[N];
int main()
{
int n, k; cin >> n >> k;
forin(i, 1, n) cin>>a[i];
long long res = a[n] + 1 - a[1];
forin(i, 2, n) b[i-1] = a[i] - a[i-1];
sort (b + 1, b + n, greater<int>());
k = min (k, n ) ;
forin(i, 1, k-1 ) res -= b[i] - 1;
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |