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 <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int a[N];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, k;
cin >> n >> k;
k--;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = a[n] - a[1] + 1;
vector <int> v;
for (int i = 1; i < n; i++) {
v.push_back(a[i + 1] - a[i] - 1);
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (int i = 0; i < k; i++) {
ans -= v[i];
}
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... |