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 <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int n, k; cin >> n >> k; vector<int> v(n); for(int i=0;i<n;i++) cin >> v[i];
vector<int> w(n-1); for(int i=0;i<n-1;i++) w[i] = v[i+1]-v[i]-1;
sort(begin(w),end(w));
int ans = v[n-1]-v[0]+1;
for(int i=n-2;i>n-k-1;i--) ans -= w[i];
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |