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 all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int N, K; cin >> N >> K;
vector<int> a(N), d(N - 1);
for (int i = 0; i < N; i++) cin >> a[i];
for (int i = 0; i < N - 1; i++) d[i] = a[i + 1] - a[i] - 1;
int ans = a[N - 1] - a[0] + 1;
sort(d.rbegin(), d.rend());
for (int i = 0; i < K - 1; i++) ans -= d[i];
cout << ans << '\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... |