This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <map>
#include<queue>
#include<set>
#include <vector>
using namespace std;
// #define int long long int
#define vvi vector<vector<int>>
#define vi vector<int>
#define s second
#define f first
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> v(n);
vector<int> a(n-1);
for(int i = 0; i < n; i++){
cin >> v[i];
if(i > 0) a[i-1]=v[i]-v[i-1]-1;
}
int ans = n;
sort(a.begin(), a.end());
for(int i = 0; i < n-k; i++){
ans+=a[i];
}
cout << ans << 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... |