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 FOR(i, u, v) for (int i = u; i <= v; i++)
#define FORD(i, v, u) for (int i = v; i >= u; i--)
#define N 1000005
using namespace std;
int n, k, a[N], b[N], res;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("INP.TXT", "r", stdin);
cin >> n >> k;
FOR(i, 1, n) cin >> a[i];
sort(a+1, a+n+1);
FOR(i, 1, n-1) b[i] = a[i+1] - a[i];
sort(b+1, b+n);
reverse(b+1, b+n);
k--;
res = a[n] - a[1] + 1;
FOR(i, 1, k)
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... |