#include <bits/stdc++.h>
using namespace std;
#define USE_STD_IO 1
#if USE_STD_IO
#define fin cin
#define fout cout
#else
ifstream fin("txt.in");
ofstream fout("txt.out");
#endif
int n, k, i, t[100002], dif[100002], rasp;
int main() {
if(USE_STD_IO) ios_base::sync_with_stdio(false);
fin.tie(NULL);
fout.tie(NULL);
fin >> n >> k;
for(i = 1; i <= n; i++) fin >> t[i];
rasp = t[n] - t[1] + 1;
for(i = 2; i <= n; i++) {
dif[i - 1] = t[i] - t[i - 1] - 1;
}
sort(dif + 1, dif + n, greater<int>());
fout << rasp - accumulate(dif + 1, dif + k, 0LL);
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... |