#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int ali, gs;
cin >> ali >> gs;
vector<int> bjk(ali);
for (int i = 0; i < ali; i++) { cin >> bjk[i]; }
long long sivas = bjk[ali - 1] - bjk[0] + 1;
vector<int> ts;
for (int i = 0; i < ali - 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++) { sivas -= ts[i]; }
cout << sivas << "\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... |