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<vector>
#include<algorithm>
#include<set>
#include<map>
#include<utility>
#define int long long
#define INF 1000000000000000000
using namespace std;
signed main() {
int n, k;
cin >> n >> k;
vector<int>v(n);
for (auto &i : v) cin >> i;
vector<int>d(n-1);
for (int i = 0 ; i < n-1 ; i++) {
d[i] = v[i+1] - v[i];
}
sort(d.begin(), d.end());
int ans = n;
for (int i = 0 ; i < n-k ; i++) {
ans += d[i]-1;
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |