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>
using namespace std;
typedef long long int64;
const int maxn = 2e5 + 2;
int main() {
int n,k;
cin >> n >> k;
vector <int64> a (n);
vector <int64> diff (n - 1);
for (int i = 0; i < n; i++){
cin >> a[i];
if (i != 0) diff[i-1] = a[i] - a[i-1] - 1;
}
int64 rs = a[n-1] - a[0] + 1;
sort(diff.begin(), diff.end(), [] (int64 &a, int64 &b) {
return a > b;
});
for (int i = 0; i < k - 1; i++){
rs-=diff[i];
}
cout << rs << "\n";
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... |