// Header Files and namespaces
#include <bits/stdc++.h>
using namespace std;
// Code shorteners
typedef long long ll;
#define print(x) cout << x << '\n'
#define endl '\n'
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// Code
int main() {
fast;
int n, k;
cin >> n >> k;
int wyn = n;
vector<int>dist = {};
int prev;
cin >> prev;
for(int i = 2; i<=n; i++){
int ti;
cin >> ti;
dist.push_back(ti - prev - 1);
prev = ti;
}
sort(dist.begin(),dist.end());
for(int i = 0; i<n-k; i++)wyn+=dist[i];
cout << wyn << '\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... |