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;
void solve();
bool multitest();
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
clock_t TIME = clock();
int TEST = 1;
if (multitest()) cin >> TEST;
while (TEST--) solve();
cerr << "\nUsed: " << clock() - TIME << " ms\n\n";
}
bool multitest() {
return 0;
}
const int NM = 1e5 + 5;
int n, k, a[NM], b[NM];
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i < n; ++i) b[i] = a[i+1] - a[i] - 1;
sort(b+1, b+n);
long long ans = n;
for (int i = 1; i <= n-k; ++i) ans += b[i];
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |