#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
using namespace std;
signed main() { int cimbom, gs;
if (scanf("%lld %lld", &cimbom, &gs) != 2) return 0;
vector<int> bjk(cimbom);
for (int i = 0; i < cimbom; i++) {
if (scanf("%lld", &bjk[i]) != 1) return 0;
}
int ist = bjk[cimbom - 1] - bjk[0] + 1;
vector<int> ts;
for (int i = 0; i < cimbom - 1; i++) {
ts.push_back(bjk[i + 1] - bjk[i] - 1);
} sort(ts.rbegin(), ts.rend());
for (int i = 0; i < gs - 1 && i < ts.size(); i++) {
ist -= ts[i];
}
printf("%lld\n", ist);
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... |