#include <bits/stdc++.h>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
constexpr int MAX = 2e+5 + 1, INF = 2e+16, MOD = 1e+9 + 7, K = 31;
void _() {
int n, k;
cin >> n >> k;
vector <int> v(n);
for (int &i : v) cin >> i;
vector <int> x;
for (int i = 1; i < n; i++) {
x.pb(v[i] - v[i-1] - 1);
}
int res = v.back() - v[0] + 1;
sort(all(x), greater<int>());
for (int i = 0; i < min(k-1, (int)x.size()); i++) res -= x[i];
cout << res;
}
signed main() {
GOOD_LUCK
int tests=1;
// cin >> tests;
for (int i=1; i <= tests; i++) {
_();
cout << endl;
}
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... |