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 <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5+5;
int n, k;
int a[N];
int diff[N], ans;
int main()
{
cin >> n >> k;
for(int i = 0; i < n; i++)
{
cin >> a[i];
if (i != 0)
{
diff[i-1] = a[i]-a[i-1]-1;
}
}
sort(diff,diff+n,greater<int>());
ans = a[n-1]-a[0]+1;
for (int i = 0; i < k-1; i++)
{
if (i >= n)
break;
ans -= diff[i];
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |